So I'm trying to read from a text file and print each line, surrounded by two strings. For example, this is my program:
string command;
int main()
{
while (!cin.eof()) {
while (getline(cin, command)) {
cout << "Can't add element : " << command << " : invalid parameter." << endl;
}
}
}
The input file is in the form of 3 numbers of each line, like this:
1 1 1
2 2 2
5 4 9
So, the output should be:
Can't add element : 1 1 1 : invalid parameter.
Can't add element : 2 2 2 : invalid parameter.
Can't add element : 5 4 9 : invalid parameter.
Instead, it prints as:
: invalid parameter.1 1 1
: invalid parameter.1 2 2
: invalid parameter.5 4 9
For the life of me I cannot figure out why this is happening. Any help?