I tried to run your code with two additional cout
s in your if
, to see what happens when for example user enters put a b
.
So, this is my code:
string line;
stringstream ss;
while (true)
{
getline(cin, line);
//i dont know if next line should be used
ss << line;
if (line.size() == 0)
continue;
string command;
ss >> command;
if (command == "put")
{
string your_file_ad, destin_ad;
ss >> your_file_ad >> destin_ad;
cout << "input #1 is " << your_file_ad << endl;
cout << "input #2 is " << destin_ad << endl;
}
}
When I run this code, then if I write put a b
in the console, I'll see this result, which is correct:
input #1 is a
input #2 is b
But it seems that this only works for the first command. after that commands couldn't process correctly.
So, I read the code again, and found out that the problem is, you are initializing your stringstream
outside of the while.
I'm not sure why exactly it doesn't work (maybe already reached EOF and can't continue reading anymore?), but if you move stringstream ss;
inside the while, it'll work correctly:
string line;
while (true)
{
stringstream ss;
getline(cin, line);
//i dont know if next line should be used
ss << line;
if (line.size() == 0)
continue;
string command;
ss >> command;
if (command == "put")
{
string your_file_ad, destin_ad;
ss >> your_file_ad >> destin_ad;
cout << "input #1 is " << your_file_ad << endl;
cout << "input #2 is " << destin_ad << endl;
}
}

Update: read @LightnessRacesinOrbit comment below about the issue with the first code.