首先是string t;
t是string变量,所以t无法与number结合在一起
第二
“ ”属于 const char* 型,但是+的左右 *** 作数必须至少一个是string变量
我编写好的代码,你看一下
#include<iostream>
#include<string>
#include<sstream>
using namespace std
int main()
{
short number=289
string t
stringstream s
s<<number
t="目前有"+s.str()+"个文件"
cout<<t<<endl
return 0
}
char *b="You are a student." 这句的意思是b指向常量串“You are a student." 的首地址而
char b[]="You are a student." 这句的意思是b数组中存存储的信息是 "You are a student."
完全不同,换句话说,这两个定义,数据存储在内存中的位置是不同的,一个在堆上(数组)一个在静态数据存储区(编译原理中有详细的代码组成描述)
而你在做copy时,往静态数组区写数据时,系统会拒绝,甚至死掉!
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)