0

I'm attempting to read a column of data from a .csv file into my C++ console application. Ideally I would like it input into an array (arr[n]) so I can manipulate the data, but it appears the commonly used getline() function only reads the values to an array (str).

I currently have:

int _tmain(int argc, _TCHAR* argv[])
{
    // Ask user for filename
    char filename[100];
    cout << "Please specify the file name";
    cin.getline(filename, 100);
    ifstream file1;
    file1.open(filename);'

// Read .csv file
string str;
int n = 0;
float arr[10000] = { 0 };

while (file1.good()) {
    getline(file1, str);
    n += 1;
    //arr[n] = ??;
}

Is there anyway I can fill an array from the .csv file.

Thanks a lot

jshep
  • 241
  • 1
  • 7
  • You may look at http://stackoverflow.com/questions/19936483/c-reading-csv-file/19936571#19936571 –  Sep 17 '15 at 16:20
  • You can convert a `std::string` representing a `float` with [`std::stof()`](http://en.cppreference.com/w/cpp/string/basic_string/stof) – NathanOliver Sep 17 '15 at 16:21

0 Answers0