1

在这里,我有一个关于 STL 的 pdf 的基本示例。为什么它不起作用?

#include "stdafx.h"
#include <vector>
#include <algorithm>
#include <iostream>
#include <iterator>

using namespace std;


int _tmain(int argc, _TCHAR* argv[])
{
    vector<string> coll;
    copy(istream_iterator<string>(cin), //start of source
            istream_iterator<string>(), //end of source
            back_inserter(coll));
    return 0;
}

错误:

ClCompile:   All outputs are up-to-date.
stl_testing1.cpp
c:\program files\microsoft visual studio 10.0\vc\include\iterator(470): error C2678: binary '>>' :
no operator found which takes a left-hand operand of type 'std::basic_istream<_Elem,_Traits>' (or there is no acceptable conversion)
          with
          [
              _Elem=char,
              _Traits=std::char_traits<char>
          ]
          c:\program files\microsoft visual studio 10.0\vc\include\istream(1053): could be 'std::basic_istream<_Elem,_Traits> &std::operator
>><std::char_traits<char>>(std::basic_istream<_Elem,_Traits> &&,signed char *)'
          with
          [
              _Elem=char,
              _Traits=std::char_traits<char>
          ]
          c:\program files\microsoft visual studio 10.0\vc\include\istream(1060): or       'std::basic_istream<_Elem,_Traits> &std::operator
>><std::char_traits<char>>(std::basic_istream<_Elem,_Traits> &&,signed char &)'
          with
          [
              _Elem=char,
              _Traits=std::char_traits<char>
          ]
          c:\program files\microsoft visual studio 10.0\vc\include\istream(1067): or       'std::basic_istream<_Elem,_Traits> &std::operator
>><std::char_traits<char>>(std::basic_istream<_Elem,_Traits> &&,unsigned char *)'
          with

我想知道有什么问题。这是一个 Win32 控制台应用程序。

4

1 回答 1

4
#include <string>

这可能会有所帮助。

于 2012-02-09T19:39:36.333 回答