| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 836 人关注过本帖
标题:新手求思路,求指点。急!!谢谢!!!
只看楼主 加入收藏
yang20110816
Rank: 1
等 级:新手上路
帖 子:11
专家分:0
注 册:2011-4-6
结帖率:25%
收藏
已结贴  问题点数:0 回复次数:2 
新手求思路,求指点。急!!谢谢!!!
声明一个表示时间的结构体,可以精确表示年,月,日,小时,分,秒;提示用户输入年,月,日,小时,分,秒的值,然后完整地显示出来。
#include <iostream>
#include <iomanip>
#include <string>
using namespace std;

struct Time{
    int year;
    int month;
    int day;
    int hour;
    int minute;
    int second;
};
int main(){
    int year,month,day,hour,minute,second;
   Time ti={year,month,day,hour,minute,second};
        cout<<"Year: "<<ti.year<<endl;
         cout<<"Month: "<<ti.month<<endl;
          cout<<"Day: "<<ti.day<<endl;
            cout<<"Hour: "<<ti.hour<<endl;
             cout<<"Minute: "<<ti.minute<<endl;
              cout<<"Second: "<<ti.second<<endl;

return 0;
}
检查出现C:\Program Files\VC++\MyProjects\p63\31.cpp(16) : warning C4700: local variable 'year' used without having been initialized
C:\Program Files\VC++\MyProjects\p63\31.cpp(16) : warning C4700: local variable 'month' used without having been initialized
C:\Program Files\VC++\MyProjects\p63\31.cpp(16) : warning C4700: local variable 'day' used without having been initialized
C:\Program Files\VC++\MyProjects\p63\31.cpp(16) : warning C4700: local variable 'hour' used without having been initialized
C:\Program Files\VC++\MyProjects\p63\31.cpp(16) : warning C4700: local variable 'minute' used without having been initialized
C:\Program Files\VC++\MyProjects\p63\31.cpp(16) : warning C4700: local variable 'second' used without having been initialized
但是可以执行;
      #include <iostream>
#include <iomanip>
#include <string>
using namespace std;

struct Time{
    int year;
    int month;
    int day;
    int hour;
    int minute;
    int second;
};
int main(){
    int year,month,day,hour,minute,second;
        cout<<"please enter the year,month,day,hour,minute,second"<<endl;
    cin>>"year: ">>"month: ">>"day: ">>"hour: ">>"minute: ">>"second: ">>endl;
    Time ti={year,month,day,hour,minute,second};
        cout<<"Year: "<<ti.year<<endl;
         cout<<"Month: "<<ti.month<<endl;
          cout<<"Day: "<<ti.day<<endl;
            cout<<"Hour: "<<ti.hour<<endl;
             cout<<"Minute: "<<ti.minute<<endl;
              cout<<"Second: "<<ti.second<<endl;

return 0;
}
    这个检查出现一个错误
error C2679: binary '>>' : no operator defined which takes a right-hand operand of type '' (or there is no acceptable conversion)
      求解释!!
搜索更多相关主题的帖子: 结构体 时间 用户 
2011-04-06 22:56
qq1023569223
Rank: 19Rank: 19Rank: 19Rank: 19Rank: 19Rank: 19
来 自:湖南科技大学
等 级:贵宾
威 望:26
帖 子:2753
专家分:13404
注 册:2010-12-22
收藏
得分:20 
#include <iostream>
#include <iomanip>
#include <string>
using namespace std;

struct Time{
    int year;
    int month;
    int day;
    int hour;
    int minute;
    int second;
};
int main()
{
    int year=2011,month=4,day=7,hour=9,minute=0,second=0;  //编译器的意思是你的变量在使用前没有赋值
    Time ti={year,month,day,hour,minute,second};
        cout<<"Year: "<<ti.year<<endl;
        cout<<"Month: "<<ti.month<<endl;
        cout<<"Day: "<<ti.day<<endl;
        cout<<"Hour: "<<ti.hour<<endl;
        cout<<"Minute: "<<ti.minute<<endl;
        cout<<"Second: "<<ti.second<<endl;

   return 0;
}

   唯实惟新 至诚致志
2011-04-07 08:52
yang20110816
Rank: 1
等 级:新手上路
帖 子:11
专家分:0
注 册:2011-4-6
收藏
得分:0 
回复 2楼 qq1023569223
谢啦,明白!!
 我第一种的也明白了,我在“>>second”后面多了个“>>endl;” 错在这了。
 
2011-04-07 20:53
快速回复:新手求思路,求指点。急!!谢谢!!!
数据加载中...
 
   



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

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