for eachの使い方
Posted: 2013年3月17日(日) 01:30
for each文を使うために
のようにすると、for each (int str in vec) の"vec"の部分に波線が引かれ、
std::vector(int, std::allocator<int>>::iterator std::vector<int, std::allocator<int>>::begin()
+1 オーバーロード
Error: "std::vector<int, std::allocator<int>>"型の式では'for each'ステートメントは実行できません
というエラーが表示されます。どうすればいいのでしょうか?
VisualStudio2012です。
#include <iostream>
#include <vector>
#include <string>
using namespace std;
int main()
{
vector<string> vec;
vec.push_back("for");
vec.push_back("each");
for each (int str in vec) {
cout << str << endl;
}
return 0;
}
std::vector(int, std::allocator<int>>::iterator std::vector<int, std::allocator<int>>::begin()
+1 オーバーロード
Error: "std::vector<int, std::allocator<int>>"型の式では'for each'ステートメントは実行できません
というエラーが表示されます。どうすればいいのでしょうか?
VisualStudio2012です。