I am trying to read in the message I Love C++ & Loops!!! from a file in to a string variable and than print each letter of the message starting from the first letter using a for loop. I managed to print them but kept getting an error. please help
Here is what the output should look like.
------------------------------------------------------------
Task 6 - For Loop String building
------------------------------------------------------------
I
I
I L
I Lo
I Lov
I Love
I Love
I Love C
I Love C+
I Love C++
I Love C++
I Love C++ &
I Love C++ &
I Love C++ & L
I Love C++ & Lo
I Love C++ & Loo
I Love C++ & Loop
I Love C++ & Loops
------------------------------------------------------------
Here is my code
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39
|
//Task 6 - Substring printing
//Output a divider
cout << setfill('*') << setw(SCREEN_WIDTH) << ' '
<< setfill(' ') << endl;
cout << "Task 6 - For Loop String building" << endl;
//Output a divider
cout << setfill('*') << setw(SCREEN_WIDTH) << ' '
<< setfill(' ') << endl;
//Move the input cursor to the next line
fin.ignore(100, '\n');
getline(fin, message, '\n');
messageLength = message.length();
for (counter = 0; counter <= messageLength; counter++)
{
messageLetter = message.at(counter);
cout << messageReconstructed << endl;
messageReconstructed.append(messageLetter);
//cout << messageReconstructed << endl;
cout << endl;
}
//Output a divider
cout << setfill('*') << setw(SCREEN_WIDTH) << ' '
<< setfill(' ') << endl;
|
Here is my output.
------------------------------------------------------------
Task 6 - For Loop String building
------------------------------------------------------------
I
I
I L
I Lo
I Lov
I Love
I Love
I Love C
I Love C+
I Love C++
I Love C++
I Love C++ &
I Love C++ &
I Love C++ & L
I Love C++ & Lo
I Love C++ & Loo
I Love C++ & Loop
I Love C++ & Loops
------------------------------------------------------------
Here is the error that I kept getting.
http://i.imgur.com/VdnBLat.jpg