我試圖編譯這個代碼片段,但我得到了編譯器錯誤:(與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