I am trying to read data into an array from a text file. The data consists of several lines of doubles. For example lines like this:
0.019017584 -0.030264859 0.035091022 1.007338638 3.179054965 0.020865514 0.311854030
Now I was thinking to read the two-dimensional data table into a one-dimensional array and to then access them linearly. This is what I tried, but it doesn't work. I am a beginner in C++. Could anyone please help?
#include "stdafx.h"
#include <iostream>
#include <fstream>
using namespace std;
const int N = 500*7;
int main()
{
ifstream dataFile("C:\\Users\\Me\\Desktop\\Data.txt");
short i = 0;
int * data = new int[N];
double x;
while (!dataFile.eof())
{
dataFile >> x;
data[i] = x;
i++;
}
dataFile.close(); //closing the file
cout << data;
delete[] data;
return 0;
}