Hello,
when i try to use the down mentioned code to read from text file "sample below" the code doesn't read from the beginning of the file and not from the beginning of the line ,it reads random.
Can any one help?
Thanks in advance
void read(){
string line;
ifstream myfile ("trafficFlow.txt");
if (myfile.is_open())
{
while (! myfile.eof() )
{
//getline (myfile,line);
myfile >> line;
char * cstr, *p;
string str (line);
cstr = new char [str.size()+1];
strcpy (cstr, str.c_str());
// cstr now contains a c-string copy of str
p=strtok (cstr," ");
while (p!=NULL)
{
cout << p << endl;
p=strtok(NULL," ");
}
delete[] cstr;
}
myfile.close();
}
else cout << "Unable to open file";
}
//////////////////////////////////////////
0.99 3864 62 r
0.84 4864 60 r
1.13 6013 56 l
1.43 7013 61 r
0.58 10458 48 l
1.27 11458 66 l
0.68 14577 52 r
0.65 15577 62 l
0.80 16577 58 r
1.33 17760 54 r
1.03 19055 40 l
0.97 21285 60 r
1.39 24051 56 l
0.63 26667 49 r
1.14 27667 50 l
0.76 34130 53 l
1.10 39123 59 l
1.04 40647 47 r
0.69 41647 47 l
1.22 48101 47 l
1.24 49445 56 r
0.65 50928 52 r
1.25 53440 48 r
0.70 55998 62 r
1.24 56998 63 l
0.77 57998 53 r
0.77 60542 57 r
0.91 64804 51 r
1.46 67797 60 l
1.43 68797 54 r
0.94 70843 53 l
1.11 73633 47 r