I'm having problems with the code below, it compiles but no matter what I do it doesn't open the .csv file that I want it to. The file name is passed into this funtion then it must read the values in and then print them out, simple, yet I cant get it to work. I'm new to C++ so please be patient, I really need help with this!
void graph_file(const char* filename )
{
cout << filename << endl; //check that file name was read correctly
ifstream newFile ; // make an object of the input file stream class
newFile.open(filename, ifstream::in); // open the file
float yVal [1025]; // float array to store incoming y-values
int count = 0;
if (newFile.good()) // if file was opened
{
while (!newFile.eof()) // read until end of file (eof)
{
for(int n = 0; n<1024; n++)
{
newFile >> yVal [n];
count++; // store floats in file to yVal array
}
}
for (int z = 0; z<count; z++) // print it if valid
{
cout << "READ: " << yVal[z] << endl;
}
newFile.close();
}
else cerr << "File not found.\n";
}