欢迎大家挑刺
c++吧
全部回复
仅看楼主
level 9
影圣天 楼主
#include<iostream>
#include<string>
using namespace std;
int main()
{
string string1="ABCDEFGHI";
const char *c_str1=NULL;
int length=string1.length()+1;
char*c_str2=new char [length];
string1.copy(c_str2,length,0);
c_str2[length]='\0';
c_str1=string1.data();
cout<<"string1="<<string1.c_str()<<endl;
cout<<"c_str1=";
//cout<<string1<<endl; //错误
for (int i=0;i<length;i++)
cout<<c_str1[i];
cout<<endl<<"c_str2="<<c_str2<<endl;
return 0;
}
以上是源码。欢迎挑刺[哈哈]也多注意下书中的程序解释
2016年01月03日 08点01分 1
level 9
影圣天 楼主
2016年01月03日 08点01分 2
level 9
影圣天 楼主
[呵呵]
2016年01月03日 08点01分 3
是我水平高了还是大家都懒的理我了?[疑问]
2016年01月03日 10点01分
level 8
2016年01月03日 10点01分 4
[滑稽][茶杯]
2016年01月03日 10点01分
level 12
int length=string1.length();
char*c_str2=new char [length+1];
string1.copy(c_str2,length,0);
c_str2[length]='\0';
2016年01月03日 10点01分 5
level 12
楼主这越界越得。。
2016年01月03日 10点01分 6
[真棒]还有呢?
2016年01月03日 10点01分
我的教材错误可不止这么一点哦[开心]
2016年01月03日 10点01分
@影圣天 内存泄露,奇葩注释。用裸指针算不算。。
2016年01月03日 10点01分
@l-zh 哈哈[真棒]厉害 全给你找出来了[玫瑰]
2016年01月03日 10点01分
level 11
我这是伪代码[滑稽]
(向算法导论学习[滑稽])
=======================
吧里的人都给我小心点!! 我不管你们是什么人,什么背景,什么身份,混的有多风生水起,我都不在意,我唯一在意的是:
经验!经验!还是经验!!\^O^/
不要惧怕权限,一起水到极限!
2016年01月03日 14点01分 7
[啊]竟然水起等级比我还高
2016年01月03日 14点01分
回复 影圣天 :[滑稽]
2016年01月03日 15点01分
1