| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 761 人关注过本帖
标题:在C++中使用函数gets()为什么会出现错误?
只看楼主 加入收藏
joky
Rank: 1
等 级:新手上路
帖 子:1
专家分:0
注 册:2006-3-15
收藏
 问题点数:0 回复次数:0 
在C++中使用函数gets()为什么会出现错误?

近日我在做一个运算符重载的程序,虽然在编译和连接时都没有问题,而且出来的结果也是正确的.可是在出来结果后就弹出一个错误窗口.我不知是什么原因.请各位编程高手指点.在线等候.急!!!!!
下面是我的程序:
#include<iostream.h>
#include<string.h>
#include<stdio.h>
#include<math.h>

class String
{
char *str;
int length;
public:

String(char*s="")
{
str=new char[strlen(s)+1];
strcpy(str,s);
}

friend String operator+(String s1,String s2);
void print()
{
cout<<endl;
cout<<str<<endl;
}
};

String operator +(String s1,String s2)
{
String t;
cout<<"please input the first string:"<<endl;
gets(s1.str);
getch(
cout<<endl;
cout<<"please input the second string:"<<endl;
gets(s2.str);
t.str=new char[strlen(s1.str)+1+strlen(s2.str)+1];
strcpy(t.str, s1.str);
strcat(t.str, s2.str);
return t;
}
int main(int argc, char* argv[])
{
String s1,s2,s3;
s3=s1+s2;
s3.print();
return 0;
}

搜索更多相关主题的帖子: 函数 gets 
2006-03-15 16:55
快速回复:在C++中使用函数gets()为什么会出现错误?
数据加载中...
 
   



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

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