如:string s1("hello");
    cout << s1;
这样就报错。
请指点。
谢谢。

解决方案 »

  1.   

    试一下 string s1="hello";
      

  2.   

    string s1 = "hello";
    也不行。
    报错:
    F:\C++2010入门经典例题\CPrimer001\CPrimer001.cpp(11) : error C2065: 'cout' : undeclared identifier
    F:\C++2010入门经典例题\CPrimer001\CPrimer001.cpp(11) : error C2784: 'class std::basic_ostream<_E,_Tr> &__cdecl std::operator <<(class std::basic_ostream<_E,_Tr> &,const class std::basic_string<_E,_Tr,_A> &)' : could not deduce template argument for 
    'class std::basic_ostream<_E,_Tr> &' from 'int'
    F:\C++2010入门经典例题\CPrimer001\CPrimer001.cpp(11) : error C2784: 'class std::basic_ostream<_E,_Tr> &__cdecl std::operator <<(class std::basic_ostream<_E,_Tr> &,const short *)' : could not deduce template argument for 'class std::basic_ostream<_E,
    _Tr> &' from 'int'
    F:\C++2010入门经典例题\CPrimer001\CPrimer001.cpp(11) : error C2784: 'class std::basic_ostream<_E,_Tr> &__cdecl std::operator <<(class std::basic_ostream<_E,_Tr> &,const unsigned char)' : could not deduce template argument for 'class std::basic_ostre
    am<_E,_Tr> &' from 'int'
    F:\C++2010入门经典例题\CPrimer001\CPrimer001.cpp(11) : error C2784: 'class std::basic_ostream<_E,_Tr> &__cdecl std::operator <<(class std::basic_ostream<_E,_Tr> &,const unsigned char *)' : could not deduce template argument for 'class std::basic_ost
    ream<_E,_Tr> &' from 'int'
    F:\C++2010入门经典例题\CPrimer001\CPrimer001.cpp(11) : error C2784: 'class std::basic_ostream<_E,_Tr> &__cdecl std::operator <<(class std::basic_ostream<_E,_Tr> &,const signed char)' : could not deduce template argument for 'class std::basic_ostream
    <_E,_Tr> &' from 'int'
    F:\C++2010入门经典例题\CPrimer001\CPrimer001.cpp(11) : error C2784: 'class std::basic_ostream<_E,_Tr> &__cdecl std::operator <<(class std::basic_ostream<_E,_Tr> &,const signed char *)' : could not deduce template argument for 'class std::basic_ostre
    am<_E,_Tr> &' from 'int'
    F:\C++2010入门经典例题\CPrimer001\CPrimer001.cpp(11) : error C2784: 'class std::basic_ostream<_E,_Tr> &__cdecl std::operator <<(class std::basic_ostream<_E,_Tr> &,_E)' : could not deduce template argument for 'class std::basic_ostream<_E,_Tr> &' fro
    m 'int'
    F:\C++2010入门经典例题\CPrimer001\CPrimer001.cpp(11) : error C2784: 'class std::basic_ostream<_E,_Tr> &__cdecl std::operator <<(class std::basic_ostream<_E,_Tr> &,const _E *)' : could not deduce template argument for 'class std::basic_ostream<_E,_Tr
    > &' from 'int'
    F:\C++2010入门经典例题\CPrimer001\CPrimer001.cpp(11) : error C2677: binary '<<' : no global operator defined which takes type 'class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> >' (or there is no acceptable conver
    sion)
    执行 cl.exe 时出错.
      

  3.   

    是这个提示:
    no operator defined which takes a right-hand operand of type 'class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> >' (or there is no 
    acceptable conversion)
      

  4.   

    在文件头部 ,include下面加 #include <iostream>
    using namespace std;
      

  5.   


    #include <iostream>
    #include <string>
    using namespaace std;
      

  6.   

    谢谢。我包含了,#include<iostream.h>
    为什么不行。
    谢谢。
    现在编译过了。
      

  7.   

    #include <iostream>
    #include <string>
    using namespaace std;或者是
    std::cout << ...楼主要好好学习哇
      

  8.   

    #include <iostream>
    #include <string>
    using namespace std;
     
    必须加上这个代码才可以用
      

  9.   

    namespace:命名空间。 C++标准程序库中的所有标识符都被定义于一个名为std的namespace中。
    当使用<iostream.h>时,相当于在c中调用库函数,使用的是全局命名空间,也就是早期的c++实现;c++标准为了和C区别开,也为了正确使用命名空间,规定头文件不使用后缀.h,当使用<iostream>的时候,该头文件没有定义全局命名空间,必须使用namespace std;这样才能正确使用cout。 
      

  10.   

    #include <iostream>
    #include <string>using namespace std;
    int main(void)
    {
       string str("hello");   cout<<str<<endl;   return 0;
    }
      

  11.   

    你是新建的控制台程序吧在 cout<<str<<endl; 下面加个 getchar();不然dos界面一闪而过看不到结果的