c++ 调试无错的程序,为什么有时候能用,有时候出乱码?

来源:百度知道 编辑:UC知道 时间:2024/09/21 01:22:26
运行1.录入个人信息时有时会出乱码.请高手解答

# include <iostream.h>
# include <fstream.h>
# include <string.h>
# include <iomanip.h>

class Record
{public:
char name[20]; // 姓名
char tel[12]; // 电话
char email[20]; // E-mail地址
int year,month,day;//生日
void readfile(int a);
void shuru();
void xieru();
void xingqi(int xq);
void xingqi1(int year2);
void sendemail() ;
void sort1(Record *);
void sort2(Record *);
};

void Record::shuru() //输入个人信息
{cout<<"输入姓名:(20字以内)"; cin>>name;
cout<<"输入生日:(年月日用空格隔开)"; cin>>year>>month>>day ;
//if (month<1||month>12||day<1||day>31)
cout<<"输入email:(20字以内)"; cin>>email;
cout<<"输入电话:"; cin>>tel;
}

void Record::readfile(int a)

输入中文还是英文时出现的?

应该是这样的原因。我写一个小的case你就应该明白了
#include <iostream>
using std::cin;
using std::cout;

int main()
{
int a,b;
cout << "input a nunber\n";
cin >> a;
cout << "input another number\n";
cin >> b;
cout << "a:" << a << "\tb:" << b << "\n";
return 0;
}

假如开始输入一个非法的数字 比如 58e
接着程序发生了什么,你就知道你的程序的那个bug所在了。
应该是输入流的问题。

发过来看下
songnan@fulong.com.cn

把你的程序补全好吗?谢谢