reading column by column

Hi,

I would like to read word by word column by column from txt file.

my db.txt file:

1
2
0.35	0.21	0.11	0.76	0.62	0.46	0.96	0.84	0.6800000000000001
0.65	0.79	0.89	0.24	0.38	0.54	0.04	0.16	0.32


I couldn't find any directions how can I do that.

Right now, I have code which reads each line till end of the file.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
int main()
{
	
	double prob;
	//string fileName;
	ifstream infile; 
	
	string path = "data\\VEdu.txt";
	infile.open(path.c_str()); 

   if (!infile) {
    cerr << "Unable to open file";
    exit(1);   // call system to stop
	}
	while (! infile.eof() ) // .eof -end-fo-file return true when reach the end of file
	{
   //cout << "Reading from the file" << endl; 
	infile >> prob; 
	cout << prob << "	" <<endl;
    
   
	}
	
	infile.close();

}

Do you have any suggestion ???

Thanks
I would take the following format for the file
1
2
0.35,0.21,0.11,0.76,0.62,0.46,0.96,0.84,0.6800000000000001
0.65,0.79,0.89,0.24,0.38,0.54,0.04,0.16,0.32


than read each line into a variable of type string
than split the string into an array of type string( or a vector of type string)
and finally convert each element of the array/vector into a double
by using atof
It's not really practical to read a file "column by column".. especially when you're reading "word by word."

Perhaps you could be a little clearer about what you're trying to accomplish.

Thanks, it is a good idea, but I have to read one element at time not a line. :(
So, the sequence is:

1 read first element from column 1
2 use it as an argument in my different function (let be X)
3 read next element from 1 column
4 call function X with element 2

and so on

Thanks
Topic archived. No new replies allowed.