Hi,
I am just learning about using fstream, I have succesfully opened a text file, the next part of what I want to do is first of all only use the first 4 lines of text from it, but then search for certain values within those 4 lines. Example... Lets pretend below is a text file:
1.Random irrelevent text here $500.22+$200.33 More random irrelevent text
2.Random text here 50-people more random text
3.user ben
4.user rando
5.werwerewrewr
6.werewrwerewrewr
7.ewrewrwerwerwerwer
8.hundreds more lines of irrelevent text.
I numbered each line just for the sake of this post so the text file has hundreds and hundreds of lines of codes but I am only interested in the first 4 lines, how do I set fstream to only scan that for effeciency?
Second of all from line 1. I only want the values $500.22 and the value $200.33 (stored seperatley in variables)
Next I want line 2 to do a check that it contains the string "50-people"
And lastly I just want check line 3 or 4 contains "user ben"
How would I go about this using fstream?
Cheers,
Ben.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19
|
#include <iostream>
#include <fstream>
using namespace std;
int main ()
{
fstream handHistory;
handHistory.open ("test.txt" ,ios::in) ;
if (! handHistory.is_open () )
{
cout << "unable to open file" << endl;
}
system("PAUSE");
}
|