I am new in c++.

I need to read a text file containing something like this data:

0.6662  0.5435  0.5545  0.55487
0.4346  0.7698  0.8965  0.56438
...
...

It is 100 rows and 4 columns

I write the following codes:

#include <iostream>
#include <fstream>
#include <string>

using namespace std;
//The main program
int main()
{
    double str[100][4];
    string xx;
    ifstream myfile("testfile.txt");
    while(!myfile.eof()){
        getline(myfile, xx, ' ');
        for (int i = 0; i < 100; i++){
            for (int j = 0; j < 4; j++){
                str[i][j] = atof(xx.c_str());
            }
        }
    }
    myfile.close();
    system("pause");
}

I checked the matrix str, it just give me first column repeatedly. I am no where close to the answer. Please help...

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.