I am in a situation where i had a loop and everytime it reads a string but I dont know how to read blank input i.e if user enter nothing and hit enter, it remains there.
I want to read that as string and m开发者_C百科ove to next input below is the code
int times = 4;
while(times--)
{
string str;
cin>>str;
---then some other code to play with the string---
}
You would need to read the entire line using getline(). Then you would need to tokenize the strings read.
Here is a reference on using getline and tokenizing using stringstream.
char blankline[100];
int times = 4;
while(times--)
{
//read a blank line
cin.getline(blankline,100);
---then some other code to play with the string---
}
精彩评论