我试图编译这个代码片段,但我得到了编译器错误:(与Visual Studio编译2010无法访问矢量
#include <vector>
#include <string>
#include <sstream>
#include <iterator>
#include <iostream>
using namespace std;
int main() {
string s("Well well on");
istringstream in(s);
vector<string> v(istream_iterator<string>(in), istream_iterator<string>());
copy(v.begin(), v.end(), ostream_iterator<string>(cout, "\n"));
}
错误:
Error 1 error C2228: left of '.begin' must have class/struct/union c:\visual studio 2008 projects\vector test\vector test\main.cpp 13 vector test
Error 2 error C2228: left of '.end' must have class/struct/union c:\visual studio 2008 projects\vector test\vector test\main.cpp 13 vector test
什么发生了什么?矢量构建正确,我怎么能不能称之为它?
此致敬礼,
你应该看看“The Definitive C++ Book Guide and List”http://stackoverflow.com/questions/38824 2/the-definitive-C++ - book-guide-and-list,“Effective STL”,尤其是 – 2010-12-22 17:28:58
再次感谢sbi;) – Chan 2010-12-22 18:21:53