I have written this simple program in C++ to print the contents of a .txt file.
void printrules(){
string rule_path = "myfiles/rulebook.txt";
ifstream fin;
fin.open(rule_path.c_str());
if (fin.fail()){
cout << "Sorry, there was an error in displaying the rules." <<endl;
}
string x;
while (fin >> x)
cout << x << " ";
fin.close();
}
int main(){
printrules; }
But I cannot think of a way to stop the words from getting 'cut' when they are output to the console. For example:
In the first line, 'h' and 'e' got separated and the same thing happened for the last words in the second and third lines too. Is there a way to make sure the words remain whole without making the length of the lines fixed? Thanks in advance :)
Aucun commentaire:
Enregistrer un commentaire