ポインタをゼロに戻すことができないため、エコー後に再びデータを通過できます。ポインタをゼロに戻すことができません
ベイリーM CC 68 ハリソンF CC 71 グラントM UN 75 ピーターF UN 69 スーM UN 79 ボウルズM CC 75 アンダーソンF UN 64:ここ
#include <iostream>
#include <fstream>
#include <string>
#include <iomanip>
using namespace std;
int main()
{
ifstream infile;
infile.open ("scores.txt" , ifstream::in);
int ch = infile.get();
string lastname;
char gender= ' ';
string collegetype;
float score=0;
float scoreMALE=0;
float scoreFEMALE=0;
int countMALE=0;
int countFEMALE=0;
while (!infile.eof())
{
cout << (char) ch;
ch = infile.get();
}
infile.seekg(0,ios::beg);
while (!infile.eof())
{
infile>>lastname>>gender>>collegetype>>score;
if(gender == 'm')
{
scoreMALE = scoreMALE + score;
countMALE++;
}
else if (gender == 'f')
{
scoreFEMALE = score;
countFEMALE++;
}
}
cout<<"\n\n\n The total Female Scores is"<<countFEMALE<<"\n\n\n The total of the male scores is"<<countMALE; // Checking to see if file works
infile.close();
cout<<"Press <Enter> to Exit";
cin.ignore();
cin.get();
return 0;
}
は、入力ファイルです グエンF CC 68 シャープF CC 75 ジョーンズM UN 75 マクミランF UN 80 ガブリエル・F UN 62
コードにはポインタがありません。 –
申し訳ありませんが、あなたの質問は不明です。あなたは一度それを読んだ後にファイルの先頭にファイルポインタを戻すように頼んでいますか?もしそうなら、あなたはすでにそのコードを持っています(あなたはそれを一度行います)。 –
第2ラウンドの前に 'infile.clear();'を追加します。 –