If this is your first visit, be sure to
check out the FAQ by clicking the
link above. You may have to register
before you can post: click the register link above to proceed. To start viewing messages,
select the forum that you want to visit from the selection below.

work with text file

Hello, I have a text file where in each line is 3 words and 2 int type numbers. I'm doing search by word and I want to print out to the screen the whole line where that word was found (the words is repeated in some lines). My search looks like this:

Re: work with text file

Originally Posted by martynasj

How to save whole line in vector, is there a function for that?

You don't need to "save whole line in vector". Just save one line a time in some string object. Then parse this string object to search for the words you are interesting in!
If such a word has been found - print out the whole string containing the line. If not - read in the next line to the same string object.

Re: work with text file

Re: work with text file

Parsing is to break apart one item into its constituent parts. So if you read a complete line from the file into a string called line, then parsing is to obtain from the string line the individual 3 words as strings (you don't need to obtain the 2 ints as you don't use them).

Alternativly, you could just read from the file the 3 words and the 2 ints as seperate variables (3 strings and 2 ints) (fin >> s1;fin >> s2;fin >> s3; fin >> i1; fin >> i2 and then compare each of the strings read (s1, s2, s3) against the search word. If found then just print the 3 strings and the 2 ints.

All advice is offered in good faith only. You are ultimately responsible for effects of your programs and the integrity of the machines they run on.

* The Perfect Platform for Game Developers: Android
Developing rich, high performance Android games from the ground up is a daunting task. Intel has provided Android developers with a number of tools that can be leveraged by Android game developers.

* The Best Reasons to Target Windows 8
Learn some of the best reasons why you should seriously consider bringing your Android mobile development expertise to bear on the Windows 8 platform.