1
マップをC++で連想コンテナとして使用しようとしています。私は直接C++ Primerのうち、この例をコピー:C++ - map-error: 'class int'以外の 'w'のメンバ 'first'へのリクエスト
#include <stdio.h>
#include <iostream>
#include <string>
#include <map>
using namespace std;
int main()
{
map<string, size_t> word_count;
string word;
while (cin >> word)
++word_count[word];
for (const auto &w : word_count)
cout << w.first << " occurs " << w.second << ((w.second > 1) ? " times" : " time") << endl;
return 0;
}
私は試してみて、それを実行すると、私は「エラーを取得:非クラス型である 『最初の』 『W』のメンバーの要求、 "のconst int型" C++ Primerの著者は、GNU 4.7.0を使用していると述べています。私はminGW(TDM-GCC-32)とVisual C++ 14を使ってみました。なぜこのエラーが出ますか?
は再現することはできません。実際のコードを入力してください。 – SergeyA
これはGCCとClangの両方で[Coliru](http://coliru.stacked-crooked.com/)でコンパイルされます。 – chris
コンパイラがC++ 11モードに設定されていることを確認してください。 –