while( getline( infile2, temp2 ) )
{
size_t prev_pos = 0, pos = 0;
while( (pos = temp2.find(' ', pos)) != std::string::npos )
{
string wordtobold( temp2.substr(prev_pos, pos-prev_pos) );
cout << wordtobold << '\n';
prev_pos = ++pos;
}
string wordtobold(temp2.substr(prev_pos, pos-prev_pos) ); // Last word
cout << wordtobold << '\n';
return 0;
}
i am going to tokenize my string, which is read from a file,
but my output is blank, why?
And i have tried to remove the getline while loop, like this and it gives correct output, why??
string temp2 ("THIS IS A SENTENCE");
size_t prev_pos = 0, pos = 0;
while( (pos = temp2.find(' ', pos)) != std::string::npos )
{
string wordtobold( temp2.substr(prev_pos, pos-prev_pos) );
cout << wordtobold << '\n';
prev_pos = ++pos;
}
string wordtobold(temp2.substr(prev_pos, pos-prev_pos) ); // Last word
cout << wordtobold << '\n';
return 0;
how can i read several line in file and tokenize each line?