Hi guys, I just started practicing C++.
Right now I'm trying to put lines of text to a file one by one manually and then stop puting in text by typing end. The thing is that I don't really know how to put the whole line of text one by one into a file and then stop the input by typing a command like "end"...
#include<iostream>
#include<fstream>
using namespace std;
int main()
{
char filename[30];
string sentence;
int i = 2;
Yes ofc, thank you! I changed my code to this and now the input and the break out of the loop works. But I have a new problem, I output the "Row number" one time too much. It seems like the program is going through the loop one time at the beginning to check ( text != "end" ) and this gives me one "Row number" too much at the beginning.
1 2 3 4 5 6 7
while (text != "end")
{
cout << "Row " << i << ": ";
getline(cin, text);
outputfile << text << endl;
++i;
}
EDIT;
fixed the little probelm by doing this
1 2 3 4 5 6 7 8 9
int i = 0;
while (text != "end")
{
++i;
getline(cin, text);
outputfile << text << endl;
cout << "Row " << i << ": ";
}
But now it outputs one "Row number" too much when i jump out from the loop.
Look just before that while loop. Did you forget to delete the cout << endl << "Row 1: " line you have in your original post?
EDIT: I'm too slow for the edit. Although I don't think your fix helped. Try switching back to what you had before and get rid of the preceeding cout line.