0

特定の入力で単語が何回出現するかを数える例に従っています。これが私のコードです:

string word, the_word;
int count(0);
vector<string> sentence;
auto it = sentence.begin();
cout << "Enter some words. Ctrl+z to end." << endl;
while (cin >> word)
    sentence.push_back(word);

the_word = *sentence.begin();
cout << the_word << endl;
while(it != sentence.end()) {
    if(*sentence.begin() == the_word)
        ++count;
    ++it;
}
cout << count << endl;

私が与えている入力は、「今、今、茶色の牛、牛」です。私は 3 を期待countしていますが、代わりに 200 万の整数を取得します。私は何が欠けていますか?

4

1 に答える 1