#include<conio.h>
#include<iostream>
#include<cstring>
#include<vector>
using namespace std;
int main()
{
const string str1 = "Mary and Linda";
const string str2 = " are friends.";
string str = str1;
str += str2;
std::cout<<str<<endl;
getch();
return 0;
#include<iostream>
#include<cstring>
#include<vector>
using namespace std;
int main()
{
const string str1 = "Mary and Linda";
const string str2 = " are friends.";
string str = str1;
str += str2;
std::cout<<str<<endl;
getch();
return 0;
}
提示错误:
新建文本文档.cpp
C:\Users\WUQ\Desktop\c++ plus\新建文本文档.cpp(16) : 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 ac
ceptable conversion)
Error executing cl.exe.
删除#include<cstring>中的c即可解决