Need help, getline problem

Display all professor.

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
int main()
  {
    account Lst;
    string dismiss;
    ifstream inFile1;
	inFile1.open("Professor.txt", ios::in);
	if(!inFile1)
	{
		cout << "File could not be open !! Press any Key...";
	}
	else
	cout << "\n\n\t\t                             PROFESSOR LIST\n\n";
	cout << "===================================================================================================================\n";
	cout << "A/c no.\t      NAME\t              Date\t      Phone\t         Address\n";
	cout << "===================================================================================================================\n";
    while (!inFile1.eof())
    {
        getline(inFile1,Lst.acno1,',');
        getline(inFile1,Lst.name_pro,',');
        getline(inFile1,Lst.date1,',');
        getline(inFile1,dismiss,'"');
        getline(inFile1,Lst.phone,'"');
        getline(inFile1,dismiss,'"');
        getline(inFile1,Lst.address_pro,'"');
        Lst.report1();
    }
    inFile1.close();
  return 0;
}


Here is my class
1
2
3
4
5
6
7
8
9
10
11
class account 
{
public:
    string acno1,acno2;
    string name_pro,name_st;
    string date1,date2;
    string address_pro,address_st;
    string phone;
    string adac,proac,stac;
    string type;
}


the output at the final line it's double like this:


S1000 xxxx xxxxx 1991-08-22 0xxxxxxxxxx xxxxx xxxxx, xxxxx
xxxx xxxxx 1991-08-22 0xxxxxxxxxx xxxxx xxxxx, xxxxx

Thanks.
Verify that the input was successful after (not before) the attempted input.
1
2
3
4
5
6
7
8
9
10
11
12
13
    // while (!inFile1.eof())
    while(inFile) // while the stream is in a good state
    {
        getline(inFile1,Lst.acno1,',');
        getline(inFile1,Lst.name_pro,',');
        getline(inFile1,Lst.date1,',');
        getline(inFile1,dismiss,'"');
        getline(inFile1,Lst.phone,'"');
        getline(inFile1,dismiss,'"');
        // getline(inFile1,Lst.address_pro,'"');
        if( getline(inFile1,Lst.address_pro,'"') // if this attempt to read was successful
              Lst.report1(); // print out all the stuff that was read
    }
Thanks, it work properly.
Topic archived. No new replies allowed.