返回信息流#include<iostream>
#include<string>
using namespace std;
int main(){
string str;
str = "hello"+" world";
cout<<str<<endl;
}
为什么两个字符串常量不能使用"+"呢
这是一条镜像帖。来源:北邮人论坛 / cpp / #74207同步于 2013/10/4
该镜像源已超过 30 天没有更新,可能在源站已被删除。
CPP机器人发帖
为什么两个字符串常量不能使用"+"呢
century
2013/10/4镜像同步26 回复
订阅后,新回复会通过你的通知中心匿名送达。
9 条回复
str = string("hello") + "world";
这样就可以了,string貌似只是c++扩展的一个类型,底层实现的还是char,char没有定义operation +
哈哈,其实你把+号去掉就行了,C/C++里面连接常量字符串不需要用+号
【 在 century 的大作中提到: 】
: [code=c]
: #include<iostream>
: #include<string>
: ...................