shuangbinbin
TestView0
2013-06-19 09:03
采纳率: 50%
浏览 1.9k

C++ 新手求解。。。。。

//#include
#include

using namespace std;

#include

void main()
{
string str1 = "Eventually I stopped caring...";
string str2 = "but that was the '80s so nobody noticed.";

str1.append( str2, 25, 15 );
cout << "str1 is " << str1 << endl; 

}

F:\C text\t.cpp(13) : error C2679: binary '<<' : no operator defined which takes a right-hand operand of type 'class std::basic_string,class std::allocator >' (or there is no acceptable conversion)
Error executing cl.exe.

  • 点赞
  • 写回答
  • 关注问题
  • 收藏
  • 邀请回答

4条回答 默认 最新

  • skatysky
    skatysky 2013-06-19 13:43
    已采纳

    你这样写,需要加命名空间,在程序开头写using namespace std;
    如果你不加这句,你要输出语句就得这么写:std::cout<<"str is"<<str1<<endl;

    点赞 评论
  • boyzxscn
    boyzxscn 2013-06-25 01:59

    用的编译器或者库的版本有点低吧,试试改成:
    cout << string("str1 is ") << str1 << endl;

    点赞 评论
  • John_ToString
    John_ToString 2015-12-05 08:15

    cout << string("str1 is ") << str1 << endl;肯定可以

    点赞 评论
  • liuhannan111
    HappyerMano 2017-07-19 04:09

    需要包含#include 这个头文件吧

    点赞 评论

相关推荐