I just wanted to split the inputted string to an vector of strings. I have 2 problems:
- If I enter nothing into the console , params isn't empty (but it should be)
- If I enter a word and add a space at the end , the word gets stored into params twice.
This is my code:
std::string input;
std::string buffer;
std::vector<std::string> params;
std::cout << "Input: " ;
std::getline(std::cin, input);
std::istringstream stream;
stream.str(input);
while(!(stream.eof()))
{
stream >> buffer;
params.push_back(buffer);
}
// printing content of params
for (int i = 0; i <params.size(); i++)
{
std::cout << "Params :" << params[i] << std::endl;
}
std::cout << params.size() << std::endl;
I think the problem could be the while condition.
I would be grateful for any help you could give me.