我写了以下代码....
#include< iostream>
#include< fstream>
using namespace std;
int main()
{
ifstream in("text1.dat",ios::in);
enum choice{zero=1, credit, debit, exit};
choice your;
int balance;
char name[50];
int option;
while(cin>>option)
{
if(option==exit)
break;
switch(option)
{case zero:
while(!in.eof())
{in>>balance>>name;
if(balance==0)
cout<<balance<<" "<<name<<endl;
cout<<in.tellg()<<endl;
}
in.clear();
in.seekg(0);
break;}
// likewise there are cases for debit and credit
system("pause");
return 0;
}
在 text1.dat 中,条目是:
10 avinash
-57 derek
0 fatima
-98 gorn
20 aditya
输出是:
1 //i input this
16
27
0 fatima
36
45
55
-1 //(a)
3 //i input this
10 avinash
16
27
36
45
20 aditya
55
20 aditya //(b)
-1
我的问题是:
- 标记为“a”的输出是-1...-1 作为tellg() 的输出是什么意思?
- 标记为“b”的输出重复...为什么会这样?