I am writing a program that does various functions. The first probrem that I am
ID: 3547221 • Letter: I
Question
I am writing a program that does various functions. The first probrem that I am having is that when the program reads in the data file, it is supposed to each of the first two lines in as individual strings and then read in the data after that into an array. This is the short version of my program:
#include <iostream>
#include <fstream>
#include <string>
using namespace std;
int main ()
{
string filename;
ifstream inFile;
string qLine1;
cout<<"Please enter the file name from the listed files: "<<endl;
cout<<"CAR1.dat, CAR2.dat, CAR3.dat, or CAR4.dat)"<<endl;
cin>>filename;
inFile.open(filename.c_str());
if (!inFile.good())
{
cout<<"Could not open file"<<endl;
system ("pause");
return 1;
}
while (!inFile.eof())
{
getline(inFile, qLine1);
cout<<qLine1<<endl;
}
inFile.close();
system("pause");
return 0;
}
and the data file it is reading from looks like this:
Test vehicle: Car #1
Test date: October 26, 2007
Driver: D. Myers
0.0 0.0
0.2 5.5
0.4 15.9
0.6 30.9
This has me stumped. Any help would be greatly appreciated and an explaination would be even better! Thanks!
Explanation / Answer
You question is confusing, and I don't see your array. Could you be more specific plz?
"The first probrem that I am having is that when the program reads in the data file, it is supposed to each of the first two lines in as individual strings and then read in the data after that into an array."
What error are you getting?
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.