| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 660 人关注过本帖
标题:请教一个特菜的问题
只看楼主 加入收藏
rxgmoral
Rank: 1
等 级:新手上路
帖 子:45
专家分:0
注 册:2006-1-18
收藏
 问题点数:0 回复次数:5 
请教一个特菜的问题

请教一个特菜的问题
const char * a1="a";
const char * a2="b";
char * a3;
如何将a1和a2值相加赋给a3
最后a3的值为ab

谢谢:)

搜索更多相关主题的帖子: char const 相加 
2006-04-23 18:50
myajax95
Rank: 16Rank: 16Rank: 16Rank: 16
等 级:版主
威 望:30
帖 子:2978
专家分:0
注 册:2006-3-5
收藏
得分:0 
a1, a2 写的都不对,指针没有分配内存。

http://myajax95./
2006-04-24 11:12
p233355750
Rank: 1
等 级:新手上路
帖 子:21
专家分:7
注 册:2006-4-24
收藏
得分:0 
char*s3=new char[sizeof(s1)+sizeof(s2)-1];
strcpy(s3,s1);
strcat(s3,s2);


Borland C++ compiler 5.5 + Editplus 2.31
2006-04-24 14:33
rxgmoral
Rank: 1
等 级:新手上路
帖 子:45
专家分:0
注 册:2006-1-18
收藏
得分:0 

#include <string.h>

const char * a1="a";
const char * a2="b";
char * a3= new char[strlen(a1)+strlen(a2)+1];
strcpy(a3,a1);
strcat(a3,a2);

为什么还那么多的警告呢??
如下:
e:\备份程序库\studio\infoengine\infoengine\infoengine.cpp(153) : warning C4996: 'strcpy' was declared deprecated
d:\microsoft visual studio\vc\include\string.h(73) : see declaration of 'strcpy'
Message: 'This function or variable may be unsafe. Consider using strcpy_s instead. To disable deprecation, use _CRT_SECURE_NO_DEPRECATE. See online help for details.'
e:\备份程序库\studio\infoengine\infoengine\infoengine.cpp(154) : warning C4996: 'strcat' was declared deprecated
d:\microsoft visual studio\vc\include\string.h(78) : see declaration of 'strcat'
Message: 'This function or variable may be unsafe. Consider using strcat_s instead. To disable deprecation, use _CRT_SECURE_NO_DEPRECATE. See online help for details.'

谢谢:)

2006-04-24 15:42
fengwei31
Rank: 1
等 级:新手上路
帖 子:3
专家分:0
注 册:2006-4-25
收藏
得分:0 

#include <string.h>
#include <stdio.h>

main()
{

const char * a1="a";
const char * a2="b";
char * a3= new char[strlen(a1)+strlen(a2)+1];

strcpy(a3,a1);
strcat(a3,a2);
printf("%s\n",a3);
return 0;
}

没有问题啊

2006-04-25 01:19
rxgmoral
Rank: 1
等 级:新手上路
帖 子:45
专家分:0
注 册:2006-1-18
收藏
得分:0 

谢谢:)

2006-04-25 10:21
快速回复:请教一个特菜的问题
数据加载中...
 
   



关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.019590 second(s), 8 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved