Go4Expert

Go4Expert (http://www.go4expert.com/)
-   C++ (http://www.go4expert.com/forums/cpp/)
-   -   (C++) trouble importing numerical, non integer, data (http://www.go4expert.com/forums/cpp-trouble-importing-numerical-integer-t20714/)

lnname 21Jan2010 02:28

(C++) trouble importing numerical, non integer, data
 
i have a file called "test_data_4" which contains a single column of 20001 numerical values

"1.09964047e+001
1.10765811e+001
1.11526284e+001
1.12244983e+001
1.12921441e+001
1.13555205e+001
1.14145834e+001
1.14692903e+001
1.15196004e+001
...."

and so on

I am writting a program that reads the file and have got stuck.

Code:

#include <vector>
#include <cstdlib>
using namespace std;
int main()
 {
 ifstream infile("test_data_4.dat");
        cout << "reading from file"<<endl;
        cout<<"how many points shall we consider ";
        int N=0;cin>>N;        //the numbers of data points we shall take from the file
        vector<long> data(N);  //the vector we assemble from the file
        cout<<"reading from the file "<<endl;
        long n=2;int j=0;
        while(j<N)
            {
            infile >> n;cout<<n<<endl;
            data[j]=n;
            j++;
            }
        // Note that n is overwritten every time we loop
 infile.close();
    cout << "The file comtains the list of values:"<<endl;
        for(int i=0; i<(int) data.size(); i++)
            {cout << data[i] << endl;}
 
 return 0;
 }

It currently seems to think that all the above are simply repetitions of the number 1.

lnname 21Jan2010 03:31

Re: (C++) trouble importing numerical, non integer, data
 
Hmmnn i've tried importing various different versions of test_data_4 and it seems to import all the data up to the full stop

lnname 21Jan2010 04:12

Re: (C++) trouble importing numerical, non integer, data
 
actually problem solved; i was using longs instead of long doubles


All times are GMT +5.5. The time now is 08:03.