I have a .txt file:
Fruit name:
"Banana - yellow"
"Apple - red"
"Grape - purple"
I am trying to extract each line, and make it so that any line that begins with "
outputs the the first word in that line.
I currently have my code set up as the following:
char text_line[1000];
while(cin.good()){
std::cin.getline(text_line,1000);
if(text_line[0] == '"')
{
string instr(text_line);
std::string tok;
std::stringstream ss(instr);
while(std::getline(ss, tok, ' '))
{
cout<<"This is the first word: "<<tok<<endl;
}
}
}
My problem is that the only word that outputs is "Banana"
, which shows me that the if-statement in my while-loop is only being executed for that one line. Is there any way to overcome this? Thank you in advance!