程序如下:
#include "stdafx.h"
#include "iostream.h"
#include "stdio.h"
#include <string>using namespace std;
int main(int argc, char* argv[])
{
string str="hello";
cout<<str<<endl;
return 0;
}
编译出错:
error C2679: binary '<<' : 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)
请问如何解决?
#include "stdafx.h"
#include "iostream.h"
#include "stdio.h"
#include <string>using namespace std;
int main(int argc, char* argv[])
{
string str="hello";
cout<<str<<endl;
return 0;
}
编译出错:
error C2679: binary '<<' : 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)
请问如何解决?
{
string str="hello";
cout<<str.c_str()<<endl;
return 0;
}
#include <string>
using namespace std;int main(int argc, char* argv[])
{
string str = "hello";
cout << str << endl;
}在VC中编译肯定是没有问题的