「Ivor Horton's Beginning Programming Visual C++ 2010」を読んでいて、第 10 章の標準テンプレート ライブラリにいます。私の問題はマップコンテナにありmap<Person, string> mapname
ます。この本は、要素を追加する多くの方法を示してくれpair<K, T>
ましmake_pair()
たmapname.insert(pair)
。しかし突然、彼は次のコードで使用される要素追加手法を導入しました。
int main()
{
std::map<string, int> words
cout << "Enter some text and press Enter followed by Ctrl+Z then Enter to end:"
<< endl << endl;
std::istream_iterator<string> begin(cin);
std::istream_iterator<string> end;
while(being != end) // iterate over words in the stream
//PROBLEM WITH THIS LINE:
words[*begin++]++; // Increment and store a word count
//there are still more but irrelevant to this question)
}
示された行は私の問題です。words
それがマップであることは理解していますが、そのような初期化は見たことがありません。そして、その増分で何が起こっているのか。Ivor Horton はこれをさらに詳しく説明できなかったと思います。あるいは、少なくとも、私のような初心者を驚かせないように十分な説明をするべきでした。