I am having trouble reading in double values into an array from a file after the first iteration of the for loop, there is no more reading due to the newline character. How can I bypass this issue?
Sample of input file:
word
2.55
word <---as of now this will not read
5.66
file.open("productsIn.txt");
if(!file.is_open()){
cout << "Could not open file." << endl;
return 1;
}
if(file.is_open()){
cout << "file open" << endl;
for(int i = 0; i < MAX_COUNT; i++){
getline(file, productName[i]);
file >> prices[i];
if(file.good()){
cout << productName[i] << endl << prices[i] << endl;
}
}
}
file.close();