| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 262 人关注过本帖
标题:使用scanf函数报内存错误
只看楼主 加入收藏
weinikuaile
Rank: 1
等 级:新手上路
帖 子:7
专家分:0
注 册:2012-5-28
结帖率:0
收藏
已结贴  问题点数:5 回复次数:2 
使用scanf函数报内存错误
程序代码:
#include <iostream>
#include <stdio.h>
using namespace std;
class Date{
private:
    int year;
    int month;
    int day;
public:
    bool IsLeapYear();
    const void display();
    Date():year(1800),month(12),day(10){}
    Date(int a,int b,int c):year(a),month(b),day(c){}
    bool DateInput(){
        cout<<"请输入年份"<<"如:1900"<<endl;
        scanf("%d",this->year);
        while (this->year>9999||this->year<1000)
        {   cout<<"请重新输入年份"<<endl;
            scanf("%d",this->year);
        }
        cout<<"请输入月份"<<"如:12"<<endl;
        scanf("%d",this->month);
        while (this->month>12||this->month<1)
        {   cout<<"请重新输入月份"<<endl;
        scanf("%d",this->month);
        }
        cout<<"请输入日子"<<"如:25"<<endl;
        scanf("%d",this->day);
        while (this->day>31||this->month<1)
        {   cout<<"请重新输入日子"<<endl;
        scanf("%d",this->day);
        }

return 0;
    }
    

};
    bool Date::IsLeapYear(){
        if((year % 4 &&!( year %100)) || (year % 400 ))
    return 1;
    else
    return 0;
}
const void Date::display(){
   
    if (IsLeapYear()==1)
    {  
        cout<<this->year<<"is a leap year!"<<endl;
    }
    else
        cout<<this->year<<"is not a leap year!"<<endl;

}

void main(){
    Date date1(2008,12,2);
    Date date2(2000,12,2);
    Date date3(2100,12,2);
    date1.display();
    date2.display();
    date3.display();
    Date date4;
    date4.DateInput();
       
    

}
程序正常运行,为什么我一输入年份,就报内存错误呢?
搜索更多相关主题的帖子: 内存 color 
2012-05-29 11:23
weinikuaile
Rank: 1
等 级:新手上路
帖 子:7
专家分:0
注 册:2012-5-28
收藏
得分:0 
呵呵,找到了,粗心了,原来地址格式输错了。
2012-05-29 11:24
pangding
Rank: 19Rank: 19Rank: 19Rank: 19Rank: 19Rank: 19
来 自:北京
等 级:贵宾
威 望:94
帖 子:6784
专家分:16751
注 册:2008-12-20
收藏
得分:5 
嗯。以后要多注意。
2012-05-30 22:00
快速回复:使用scanf函数报内存错误
数据加载中...
 
   



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

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