If you use fstream its >> operator will skip all spaces and tabs for you, so that all you get are words.
ifstream in("in.txt");
std::string word;
while( in >> word)
{
// do something with this word
}
Ancient Dragon
Retired & Loving It
30,049 posts since Aug 2005
Reputation Points: 5,662
Solved Threads: 2,343
The problem with AD's solution is you never really know when you're at the beginning of a line.
You can:
Read a complete line.
Test the beginning for the word in question.
If found, there are many ways to 'parse' the line.
1) looking at each character and dealing with SPACEs and non-SPACEs as appropriate.
2) Use stringstreams to parse the line
3) use the strxxx functions.
WaltP
Posting Sage w/ dash of thyme
10,506 posts since May 2006
Reputation Points: 3,348
Solved Threads: 944
So I think I need to take this step by step... Start out with getting the line with the search term on it, and priting out that line. Any ideas on that?
Once I get the line printed out succesfully, we can figure out how to get the words I need out of the line.
This is an excellent idea. You give it a try and we'll help when you get stuck. But you have to get stuck first. Look up the methods that can be used to compare strings and get substrings.
WaltP
Posting Sage w/ dash of thyme
10,506 posts since May 2006
Reputation Points: 3,348
Solved Threads: 944