Reading Data From A File - SOLVED
many thnx to MacGyver & Daved...
Problem: i have a data file (*.txt or *.dat), N rows and 3 columns of data. Don't know the N number!
i want to read all the data from the file and see if the data are read properly.
SOLUTION
Code:
#include <iostream>
#include <fstream>
#include <vector>
#include <conio.h>
using namespace std;
int main()
{
vector<double> vList;
double data;
fstream file;
file.open("data.txt", fstream::in | fstream::out);
while(file>>data)
vList.push_back(data);
cout<<"Row Tot:"<< vList.size();
cout<<"\nX"<<"\tY"<<"\tZ"<<endl;
for(int i=0; i< vList.size()/3.; i++) // 3. : for 3 columns...
{
for(int j=0; j<3; j++)
cout<< vList[(i*3)+j]<< " ";
cout<<endl;
}
getch();
}