The essence of bydlokod: if the length of the string is more than 80 characters, the remaining words from this line are transferred to a new line.

The problem is that if a file has more than one line, then the program only works with the 1st line as many times as there are lines in total.

string s,res,out; stringstream tmp; ifstream file("LAB5_8.txt"); while (true) { getline(file,s); tmp << s; while (tmp >> s) { if(res.length()+s.length()<=80) {res += s+' '; continue;} else out+=s+' '; } cout << res+'\n' << endl; cout << out+'\n' << endl; if (file.eof()) break; } 

    1 answer 1

    And you do not drag all of the previous iterations with you. Bring in

     string s,res,out; stringstream tmp; 

    after while(true) .

    Any trifles such as extra blank lines, I think, will process yourself?

    • Thank you very much. I checked that the variables are not re-created with the new iteration) - Ski
    • @Ski, if the answer is correct, then mark it as true by pressing the green check mark to close the question - dirkgntly