iはtext1.datエントリに次のコード....ファイルストリーム処理は
#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;
}
を書いた
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'とマークされた出力が繰り返されます...なぜそうですか?
これは、次のように書き換えて簡単にすることができます。 http://www.cplusplus.com/reference/iostream/istream/tellg/ – balki
コード+出力+なぜですか? !=良いSOの質問 – AJG85
@balkiは説明が短すぎます...私は失敗が-1を返すことを知っていますが、私はEOFが直面するループが終了する...しかし、あなたが55後にも見ることができる条件を置いている出力(それはステートメントを含むステートメントがストリームに入力された後です)ループは終了せず、もう1つの出力を与えます-1 ... 3を入力すると同じことが繰り返されます。 ..uは私を下降させる前に両方とも満足に答えるべきだった – avinash