| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 3771 人关注过本帖
标题:c++中用strcpy和strcat报错
取消只看楼主 加入收藏
peswe
Rank: 1
等 级:新手上路
帖 子:197
专家分:0
注 册:2006-11-22
收藏
 问题点数:0 回复次数:7 
c++中用strcpy和strcat报错

俺是新手,菜鸟一个,刚学C++,
刚编了个字符相加的程序,功能是,将两个字符相加,例如:输入hello,和world两个字符,便输出helloworld
可是总是出错,用strcpy,和strcat函数时,也报错;
最后,编译时没错,可是运行不了,着实郁闷,望哪位高手,帮忙写个程序,让俺看看
谢谢了先!

搜索更多相关主题的帖子: strcat strcpy 
2006-11-22 22:39
peswe
Rank: 1
等 级:新手上路
帖 子:197
专家分:0
注 册:2006-11-22
收藏
得分:0 
新手,以前不知道怎么找到自己发的东西,现在才 知道了,故而特地回来感谢下
谢谢!!!

C斗士~~~fighting!!!!
2006-12-18 22:39
peswe
Rank: 1
等 级:新手上路
帖 子:197
专家分:0
注 册:2006-11-22
收藏
得分:0 
谢谢了先!!!

C斗士~~~fighting!!!!
2006-12-20 17:01
peswe
Rank: 1
等 级:新手上路
帖 子:197
专家分:0
注 册:2006-11-22
收藏
得分:0 

那顺便帮我看看下面的程序怎么总是出错:

#include <iostream.h>
#include <string.h>
class zf
{
char * str;
public:
void input()
{
cout<<"输入字符:"<<endl;
cin>>str;
}
void print()
{
cout<<str<<endl;
}
~zf()
{
delete str;
}

friend zf operator + (zf &a,zf &b);
};
zf operator + (zf &a,zf &b)
{
zf temp;
delete temp.str;
temp.str=new char [strlen(a.str)+strlen(b.str)+1];
strcpy(temp.str,a.str);
strcat(temp.str,b.str);
return temp;
}
main()
{
zf a ,b,c;
a.input();
b.input();
c=b+a;
c.print();
return 0;
}

拜托了!!!!!



C斗士~~~fighting!!!!
2006-12-20 17:04
peswe
Rank: 1
等 级:新手上路
帖 子:197
专家分:0
注 册:2006-11-22
收藏
得分:0 
总之,先谢谢了!

C斗士~~~fighting!!!!
2006-12-25 21:45
peswe
Rank: 1
等 级:新手上路
帖 子:197
专家分:0
注 册:2006-11-22
收藏
得分:0 

哇嘶!7楼的你好厉害,真的可以了,
可是我经过以下变化就错了好多错误,拜托帮我解释:

#include <iostream.h> // 这里改变了
#include <string.h>

//using namespace std;

class MyClass{
string str;
public:
MyClass(){}
MyClass(const string& str_):str(str_){}

void input(){
cout<<"please input a string: ";
cin>>str;
}

void print() const{
cout<<"The result: ";
cout<<str<<endl;
}

friend MyClass operator+(const MyClass &a,const MyClass &b){
return MyClass(a.str+' '+b.str);
}

~MyClass(){}
};

int main(){
MyClass a,b,c;
a.input();
b.input();

c=a+b;
c.print();

return 0;
}


C斗士~~~fighting!!!!
2006-12-25 21:51
peswe
Rank: 1
等 级:新手上路
帖 子:197
专家分:0
注 册:2006-11-22
收藏
得分:0 

受教了,谢谢各位!!!!!


C斗士~~~fighting!!!!
2007-01-01 09:01
peswe
Rank: 1
等 级:新手上路
帖 子:197
专家分:0
注 册:2006-11-22
收藏
得分:0 

学习了


C斗士~~~fighting!!!!
2007-01-02 17:00
快速回复:c++中用strcpy和strcat报错
数据加载中...
 
   



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

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