I'm new to C++ so please be patient with me and explain everything in plain English. I'm trying to write a code that would read data from a file and store certain values for later use.
My code currently looks like this:
The errors that I'm getting are in the CData.cpp code and are as follows:
- getline(datafile, line): Invalid arguments
- string line[0]: 'line' has a previous declaration as "std::string line[0]"
- conflicting declaration "float line[1]"
- expected initializer before "if"
I don't know how to fix these errors. I've tried declaring "line" as a string before, but that would prompt errors with the if statement.
Thank you so much in advance for any help!
The standard version of getline is expecting a string (or char buffer) as the second argument.
You could write your own implementation which takes a vector<CData>, but that might not be the right way to go. You would still have to use the normal version of getline and then convert the input to CData instances.
string line[0] is redeclaring line, this time as an array of length (which is illegal, I think. though some compilers let you get away with it...)
float line[1] is declaring line yet again, this time as an array of floats with a single element.
And there's a missing semicolon.
I am unsure about what you are trying to do in your loop...