Having trouble reading from a text file
I need to read this from a textfile, and display all of them in the cout order.
a222.5 10000.00 329238390 Matthew Charles Mullenweg
g3999 59.99 327237237 Sergey Mikhailovich Brin
x1100.1 200 100000000 Edsger Wybe Dijkstra
p51 9999.99 123456890 Guido van Rossum
c499.9 100.01 777777777 Kenneth Lane Thompson
I'm really confused with how to do this correctly
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44
|
#include <iostream>
#include <string>
#include <fstream>
#include <iomanip>
using namespace std;
int main()
{
char ch1, ch2, ch3;
float hours;
double rate;
long id;
string Firstname;
string Lastname;
string Middlename;
cout << "Name of input file: ";
string infile;
string file;
ifstream myfile;
myfile.open("infile.txt");
if(!myfile)
{
cout << "Error\n\n";
}
while(myfile)
{
cin.ignore(1);
cin.get(ch1);
cin >> hours >> rate >> id;
cin.ignore(1);
cin.get(ch2);
cin.ignore(100,' ');
cin.get(ch3);
cin.ignore(100,' ');
cin >> Lastname;
}
cout << left << setw(12) << id << left << setw(15) << Lastname << " " << ch2 << " " << ch3;
return 0;
}
|
Here :) www.cplusplus.com/doc/tutorial/files/
Hey so I'm able to get the line now, but how would I get the line that I want at the very bottom?
Because this keep showing up for some reason.
http://puu.sh/cbsOK/1062f66af2.png
Topic archived. No new replies allowed.