Thread: Reading Data From A File - Error

Threaded View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Registered User
    Join Date
    May 2007
    Posts
    7

    Unhappy 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();
    }
    Last edited by ~Stingray~; 05-18-2007 at 02:35 PM.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. xor linked list
    By adramalech in forum C Programming
    Replies: 23
    Last Post: 10-14-2008, 10:13 AM
  2. Another syntax error
    By caldeira in forum C Programming
    Replies: 31
    Last Post: 09-05-2008, 01:01 AM
  3. failure to import external C libraries in C++ project
    By nocturna_gr in forum C++ Programming
    Replies: 3
    Last Post: 12-02-2007, 03:49 PM
  4. Stupid compiler errors
    By ChrisEacrett in forum C++ Programming
    Replies: 9
    Last Post: 11-30-2003, 05:44 PM
  5. Linking error
    By DockyD in forum C++ Programming
    Replies: 10
    Last Post: 01-20-2003, 05:27 AM