Assigning values to structure in array
Suppose my employee.txt have this;
first name 1111 departmentone
second name 2222 departmenttwo
third name 3333 departmentthree
and the suppose-output is.
first name 1111 departmentone
second name 2222 departmenttwo
third name 3333 departmentthree |
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
|
#include<iostream>
#include<fstream>
using namespace std;
struct employeetype
{
string firstName, lastName, deptID;
int personID;
};
void main()
{
ifstream infile;
infile.open("employee.txt");
employeetype employees [3];
for(int counter = 0; counter < 3; counter++)
{
infile >>employees[counter].firstName>>employees[counter].lastName
>>employees[counter].personID>>employees[counter].deptID;
}
for(int counter1 = 0; counter1 < 3; counter1++)
{
cout<<employees[counter1].firstName<<"\t"<<employees[counter1].lastName<<"\t";
cout<<employees[counter1].personID<<"\t"<<employees[counter1].deptID<<endl;
}
}
|
The problem is, seems like the code doesn't process string input.
But I take this code from textbook :(
Topic archived. No new replies allowed.