c++ “+”: 不能添加两个指针

c++ “+”: 不能添加两个指针,第1张

标准的c++没有String型只有string型

首先是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时,往静态数组区写数据时,系统会拒绝,甚至死掉!


欢迎分享,转载请注明来源:内存溢出

原文地址: https://outofmemory.cn/bake/11888704.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2023-05-19
下一篇 2023-05-19

发表评论

登录后才能评论

评论列表(0条)

保存