を整数カウント、(例えば)が含まれている "例でを。":C++ - 私は名前の</em> .txtファイル<em>から整数をカウントする.txtファイルから
1 2 3 4 5
3 6 7
5 8
8 9 10 11
1.とこの場合、私には11を返します(1をカウントする整数 - ユニークな数のカウントのみ)。この時点では、0だけが出力されます(この段階でファイルを開くことに問題があると思います)。
2.プリントアウトのすべての行で唯一の最初の整数を - 1、3、5、8
int integer_count(){
int count = 0;
int i;
ifstream fin;
fin.open("Example.in"); //.txt file
while(fin >> i)
{
count++;
}
fin.close();
return count; // In this case it should print 14 instead of 11,
because I didn't count out 3, 5 and 8 (which duplicates - haven't figured
out how to make unique count that would close eye for duplicates and
just count unique integers.)
}
デバッガを使って実際に何が読み込まれているのか確認しましたか? –
読み取った要素を、特定の順序に従って固有の要素を格納するコンテナである[set](http://www.cplusplus.com/reference/set/set/)に挿入することができます。次に、あなたはセットのサイズを読みます。 – BugsFree
@AlgirdasPreidžius私はこのようなものにちょっと新しいです。私は2回チェックしましたが、目立つものは何も見ませんでした。プログラムの出力 - 0、合計の状態を開始しています。つまり、おそらくファイルを開くことさえできませんでしたが、なぜですか? – JasonM