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; }