jeudi 1 février 2018

Adding values to a double array from a file C++

I'm working on an assignment for my C++ class that requires me to read floats from a file and add them to an array. The numbers are all on the same line separated by spaces. How would I add those values to an array list of doubles (assignment requires I use doubles)? I also don't know how many numbers will be in the file.

This is what I have so far (Just importing the file )

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

using namespace std;

int main(){

double dataList[150];
bool exit = false;
string fileName;

cout << "Enter the name of the file to import:" << endl;
getline(cin, fileName);

ifstream inFile(fileName, ios::in);
if (inFile){
    cout << "Importing file: " << fileName << endl;
}
else{
    cout << "Error importing file. Please try again" << endl;
}

}

Aucun commentaire:

Enregistrer un commentaire