The problem is that you're extracting strings, which by default will extract up until the next space. So at the first iteration, keyword
is "Julia","2
. If you want to extract everything separated by commas, I suggest using std::getline
with ,
as the delimeter:
while (std::getline(file, keyword, ','))
This will look through all of the quoted strings. Now you can use std::string::find
to determine if the input word
is found within that quoted string:
while (std::getline(file, keyword, ',') &&
keyword.find(word) == std::string::npos)
Now this will loop through each quoted string until it gets to the one that contains word
.