Hi there just wondering if I am on the right track. I need to load a file in a program and then store the stata in an array. I am now testing this function to see if it is working... when I run the functioni the following happens.
1) the first number in the txt file that I open is missing. And when I set the list to < 82 (as there is 81 numbers in total) it will show the data and then say there was an error. in fact once it hits over 30 it will come up with this problem. How do I fix that??
2) also how do I get about including the first number in the file being included.
Am I on the right track?
1) the first number in the txt file that I open is missing. And when I set the list to < 82 (as there is 81 numbers in total) it will show the data and then say there was an error. in fact once it hits over 30 it will come up with this problem. How do I fix that??
2) also how do I get about including the first number in the file being included.
Am I on the right track?
Code:
int loadFile()
{
ifstream infile;
string filename;
float list = 0;
cout << "Enter file name " << endl;
cin >> filename;
infile.open(filename.c_str());
if (infile.fail())
{
cout << "File not found " << endl;
return EXIT_FAILURE;
}
string s;
infile >> filename[list];
while (infile && list >= 0 && list <9)
{
infile >> filename[list];
cout << filename[list];
list++;
}
return EXIT_SUCCESS;
}
Comment