K
Kay
I have tried to use following code to read data form a txt file. However
, I have found that it would obtain last sentence one more time. How can
I solve this problem ?
void load(istream& is) {
string temp_name, temp_cuisine, temp_mode;
while( is != NULL ){
getline(is, temp_name, ';');
getline(is, temp_cuisine, ';');
getline(is, temp_mode, '\n');
cout << temp_name;
cout << temp_cuisine;
cout << temp_mode << endl;
}
THE code display :
C:\DJGPP\myFiles\sc>a
John Jordan 6 8
Peter 5 9
Kay 2 6
Loen 8 0
Loen 8 0 <-- display one more
C:\DJGPP\myFiles\sc>
, I have found that it would obtain last sentence one more time. How can
I solve this problem ?
void load(istream& is) {
string temp_name, temp_cuisine, temp_mode;
while( is != NULL ){
getline(is, temp_name, ';');
getline(is, temp_cuisine, ';');
getline(is, temp_mode, '\n');
cout << temp_name;
cout << temp_cuisine;
cout << temp_mode << endl;
}
THE code display :
C:\DJGPP\myFiles\sc>a
John Jordan 6 8
Peter 5 9
Kay 2 6
Loen 8 0
Loen 8 0 <-- display one more
C:\DJGPP\myFiles\sc>