I'm trying to make a program that takes input from the console, and reads each word and number separated by spaces ans stores it in a vector string for further processing.
void foo() {
string input;
vector<string> list;
while (getline(cin, input, ' '))
{
list.push_back(input);
}
for (int counter = 0; counter < list.size(); counter++)
{
cout << list[counter] << endl;
}
};
int main()
{
foo();
return 0;
}
The problems comes when getline doesn't stop reading at newlines and you need to ctrl+z to EOF. Is there anyway to make getline stop at newline?
Aucun commentaire:
Enregistrer un commentaire