Hey guys and gals.
I'm struggling yet again to get my file input working. I have a text file containing:
John 19 smith 15 03 1986
Billy 15 Nomate 19 07 1990
...
etc
I'm needing to get a line in at a time but also store the variables in different types.
#include <iostream>
#include <fstream>
#include <cstring>
using namespace std;
int main()
{
ifstream infile;
char buffer[25];
char firstname[25];
infile.open("emp.txt");
if (infile.fail())
{
cerr << "error " <<endl;
exit(1);
}
char ch;
while((ch = infile.get()) !=EOF && (ch!=' '))
cout << ch;
return 0;
}
I've got this and it prints out "john" which is fair enough. But how do i get it to start doing the '19' and smith part along with the rest.
Since I'll have varibles called
char firstname[20];
char surname[20];
int age;
...etc all numbers need storing differently. (ie in each own int or char varible).
Make sence I hope so.
Thanks,
John