-
How read it by C++
Hello all:
I used to use C to do the scientific calculation. When I need to read a data file "datafile.txt" into an array "data[]", the following is available:
Code:
FILE *fp;
if((fp=fopen("0date6y.txt", "r"))==NULL)
{ printf("can not open file date\n");
return;
}
for(i=0; i<=M1; i++) fscanf(fp,"%s", &dt); //M1: elements of data
Use the script above, the data can be only one column.
If the data file has three columns, can I use C++ script to read the 2nd or 3rd column?
Thanks!
-
Huh? There is no limit on the number of columns you can have with the code you have posted. Have you tried?
But if you want to do the same thing in C++, you can do:
Code:
ifstream fp;
if (!fp.open("0date6y.txt", ios::in))
{ cout << "can not open file date\n";
return;
}
for(i=0; i<=M1; i++) cin >> dt;
--
Mats