string str="bobo";
cout<<str;
系统提示:
D:\myproject\enum\enum.cpp(54) : error C2678: binary '<<' : no operator defined which takes a left-hand operand of type 'class ostream_withassign' (or there is no acceptable conversion)
Error executing cl.exe.
么回事呢?

解决方案 »

  1.   

    应该是cout的《不支持string类型吧string str="bobo";
    char *p = (char*)str.c_str();//转换一下类型
      

  2.   

    basic_ostream& operator<<(basic_ostream& (*pf)(basic_ostream&));
        basic_ostream& operator<<(basic_ios<E, T>& (*pf)(basic_ios<E, T>&));
        basic_ostream& operator<<(ios_base<E, T>& (*pf)(ios_base<E, T>&));
        basic_ostream& operator<<(basic_streambuf<E, T> *sb);
        basic_ostream& operator<<(const char *s);
        basic_ostream& operator<<(char c);
        basic_ostream& operator<<(bool n);
        basic_ostream& operator<<(short n);
        basic_ostream& operator<<(unsigned short n);
        basic_ostream& operator<<(int n);
        basic_ostream& operator<<(unsigned int n);
        basic_ostream& operator<<(long n);
        basic_ostream& operator<<(unsigned long n);
        basic_ostream& operator<<(float n);
        basic_ostream& operator<<(double n);
        basic_ostream& operator<<(long double n);
        basic_ostream& operator<<(void * n);
    //--------------------------------------------------------
    怎么会不支持??
    #include "stdafx.h"
    #include <iostream>
    #include <string>
    using namespace std;
    int main(int argc, char* argv[])
    {
    string s("hehe");
    cout << s << endl;
    return 0;
    }
      

  3.   

    支持呀#include <iostream>
    #include <string>
    using namespace std;
    void main()
    {
    string s="Do you understand??";
    cout << s ;

    }
      

  4.   

    以下代码将可以将控制台中的一句话输入到string中string x;
    getline( cin, x );
      

  5.   

    getline出错? Standard C++ Library Reference   getlineSee Also
    <string> Members | string::getline Sample
    Extract strings from the input stream line-by-line.template<class CharType, class Traits, class Allocator>
       basic_istream<CharType, Traits>& getline(
          basic_istream<CharType, Traits>& _Istr,
          basic_string<CharType, Traits, Allocator>& _Str
    );template<class CharType, class Traits, class Allocator>
       basic_istream<CharType, Traits>& getline(
          basic_istream<CharType, Traits>& _Istr,
          basic_string<CharType, Traits, Allocator>& _Str,
          CharType _Delim
    );
    Parameter
    _Istr 
    The input stream from which a string is to be extracted. 
    _Str 
    The string into which are read the characters from the input stream. 
    _Delim 
    The line delimiter. 
    Return Value
    The first function returns getline( _Istr, _Str, _Istr.widen( '\n' ) ). The second function replaces the sequence controlled by _Str with a sequence of elements extracted from the stream _Istr. Res
    In order of testing, extraction stops: At end of file. 
    After the function extracts an element that compares equal to delim, in which case the element is neither put back nor appended to the controlled sequence. 
    After the function extracts str.max_size elements, in which case the function calls setstate(ios_base::failbit). 
    If the function extracts no elements, it calls setstate(failbit). In any case, it returns _Istr.See Also
    <string> Members | string::getline Sample--------------------------------------------------------------------------------Send feedback on this topic to Microsoft&copy; 1992-2002 by P. J. Plauger. All rights reserved.&copy; Microsoft Corporation. All rights reserved.
      

  6.   

    你要加STL的头文件的啦
    #include <iostream>
    #include <string>