So I am working on a problem and have a bit of an issue that I can't seem to figure out and would like some guidance.
I have string input coming into my program via fstream. Its a bunch of sentences where I have to cout it in such a way where each line can be no more than 40 characters. I can't hyphenate words so if a word is going to go over, the code must move it to the next line. The entirety of the program does a bunch of other stuff, but here is my void function where I have my cout statement. The function capitalizes each word and is not related to my issue.
void format(string& word)
{
word[0] = toupper(word[0]);
for (int i=1; i<word.length(); i++)
word[i] = tolower(word[i]);
cout << word+' ';
}
I have tried different types of for loops where I put an if statement that if it hits word[i] hits 40 to do a "cout << endl;" but that didn't work. I played around with setw but that was wrong, (as I should have known).
Any help to point me in the right direction will be greatly appreciated.