求调用time.h实现显示时间的功能,请 看下错误。

loong0306 2014-06-20 11:56:20
有些迷茫了,求帮助

/*
测试系统时间输入输出。
2014年6月20日 23:29:30
-------------------------
功能:想达到调用windows.h中system中的time函数。
未实现。
*/

#include<iostream>
#include<math.h>
#include<string.h>
#include<windows.h>
#include<time.h>
using namespace std;

struct time /* Gets system time */
{
time_t t;
while(1)
{
time(&t);
Sleep(1000);
system("cls");
cout<<"Today's date and time:"<<endl<<ctime(&t)<<endl;
}

}tm;

int main( int argc, char *argv[] )
{
int year;int month;int day;
int h;int min; int s;
cout<<"系统时间日期 时间 显示。请用输入后加空格"<<endl;
cout<<"请输入系统日期:"<<endl;
cin>>year >>month >>day;
cout<<"请输入系统时间:"<<endl;
cin>>h >>min >>s;
printf("-----------------------------------------------------\n");
printf("- -\n");
printf("- 系统日期: -\n");
printf("- %d年%d月%d日 -\n",year,month,day);
printf("- 系统时间: -\n");
printf("- %d时%d分%d秒 -\n",h,min,s);
printf("- -\n");
printf("-----------------------------------------------------\n");
return 0;
}

...全文
149 8 打赏 收藏 转发到动态 举报
写回复
用AI写文章
8 条回复
切换为时间正序
请发表友善的回复…
发表回复
我看你有戏 2014-06-22
  • 打赏
  • 举报
回复
引用 6 楼 u010957746 的回复:
[quote=引用 5 楼 henry3695 的回复:]


/*
	测试系统时间输入输出。
	2014年6月20日 23:29:30
	-------------------------
	功能:想达到调用windows.h中system中的time函数。
	未实现。
*/

#include<iostream>
#include<math.h>
#include<string.h>
#include<windows.h>
#include<time.h>
using namespace std;

struct mytime		/*   Gets   system   time   */	
{
	time_t t;
	mytime()
	{
		while(1)
		{
			Sleep(1000);
			system("cls");

			char szCurrentDateTime[32];     
			time_t nowtime;     
			struct tm* ptm;     
			time(&nowtime);     
			ptm = localtime(&nowtime);     
			sprintf(szCurrentDateTime, "%4d-%.2d-%.2d %.2d:%.2d:%.2d",     
				    ptm->tm_year + 1900, ptm->tm_mon + 1, ptm->tm_mday,     
				    ptm->tm_hour, ptm->tm_min, ptm->tm_sec); 


			cout<<"Today's date and time:"<<endl<<szCurrentDateTime<<endl; 
		}
	}
	
}tm;

int main( int argc, char *argv[] )
{
	struct mytime	 tt;
	
	return 0;
}


太谢谢了,我还学习到了指针的方法。3q[/quote] 要学习指针的一些用法,可以看看我做的C++视频,初学者会很有帮助 http://pan.baidu.com/s/1o6M8XCm 希望给有缘人一些帮助
loong0306 2014-06-22
  • 打赏
  • 举报
回复
引用 4 楼 czarten 的回复:
[quote=引用 3 楼 u010957746 的回复:] [quote=引用 2 楼 czarten 的回复:]

struct time        /*   Gets   system   time   */   
{
    time_t t;
    while(1)
    {
        time(&t);
        Sleep(1000);
        system("cls");
        cout<<"Today's date and time:"<<endl<<ctime(&t)<<endl; 
    }
}
这能通过编译?
求解。。[/quote] 你的main函数我来回看了好几遍,跟你上面这个struct毫无关联啊 所以struct里面写的任何东西当然不会起任何作用[/quote]看到了。。。。
loong0306 2014-06-22
  • 打赏
  • 举报
回复
引用 5 楼 henry3695 的回复:


/*
	测试系统时间输入输出。
	2014年6月20日 23:29:30
	-------------------------
	功能:想达到调用windows.h中system中的time函数。
	未实现。
*/

#include<iostream>
#include<math.h>
#include<string.h>
#include<windows.h>
#include<time.h>
using namespace std;

struct mytime		/*   Gets   system   time   */	
{
	time_t t;
	mytime()
	{
		while(1)
		{
			Sleep(1000);
			system("cls");

			char szCurrentDateTime[32];     
			time_t nowtime;     
			struct tm* ptm;     
			time(&nowtime);     
			ptm = localtime(&nowtime);     
			sprintf(szCurrentDateTime, "%4d-%.2d-%.2d %.2d:%.2d:%.2d",     
				    ptm->tm_year + 1900, ptm->tm_mon + 1, ptm->tm_mday,     
				    ptm->tm_hour, ptm->tm_min, ptm->tm_sec); 


			cout<<"Today's date and time:"<<endl<<szCurrentDateTime<<endl; 
		}
	}
	
}tm;

int main( int argc, char *argv[] )
{
	struct mytime	 tt;
	
	return 0;
}


太谢谢了,我还学习到了指针的方法。3q
我看你有戏 2014-06-22
  • 打赏
  • 举报
回复


/*
	测试系统时间输入输出。
	2014年6月20日 23:29:30
	-------------------------
	功能:想达到调用windows.h中system中的time函数。
	未实现。
*/

#include<iostream>
#include<math.h>
#include<string.h>
#include<windows.h>
#include<time.h>
using namespace std;

struct mytime		/*   Gets   system   time   */	
{
	time_t t;
	mytime()
	{
		while(1)
		{
			Sleep(1000);
			system("cls");

			char szCurrentDateTime[32];     
			time_t nowtime;     
			struct tm* ptm;     
			time(&nowtime);     
			ptm = localtime(&nowtime);     
			sprintf(szCurrentDateTime, "%4d-%.2d-%.2d %.2d:%.2d:%.2d",     
				    ptm->tm_year + 1900, ptm->tm_mon + 1, ptm->tm_mday,     
				    ptm->tm_hour, ptm->tm_min, ptm->tm_sec); 


			cout<<"Today's date and time:"<<endl<<szCurrentDateTime<<endl; 
		}
	}
	
}tm;

int main( int argc, char *argv[] )
{
	struct mytime	 tt;
	
	return 0;
}


你怎么了熊吉 2014-06-21
  • 打赏
  • 举报
回复

struct time        /*   Gets   system   time   */   
{
    time_t t;
    while(1)
    {
        time(&t);
        Sleep(1000);
        system("cls");
        cout<<"Today's date and time:"<<endl<<ctime(&t)<<endl; 
    }
}
这能通过编译?
你怎么了熊吉 2014-06-21
  • 打赏
  • 举报
回复
引用 3 楼 u010957746 的回复:
[quote=引用 2 楼 czarten 的回复:]

struct time        /*   Gets   system   time   */   
{
    time_t t;
    while(1)
    {
        time(&t);
        Sleep(1000);
        system("cls");
        cout<<"Today's date and time:"<<endl<<ctime(&t)<<endl; 
    }
}
这能通过编译?
求解。。[/quote] 你的main函数我来回看了好几遍,跟你上面这个struct毫无关联啊 所以struct里面写的任何东西当然不会起任何作用
loong0306 2014-06-21
  • 打赏
  • 举报
回复
引用 2 楼 czarten 的回复:

struct time        /*   Gets   system   time   */   
{
    time_t t;
    while(1)
    {
        time(&t);
        Sleep(1000);
        system("cls");
        cout<<"Today's date and time:"<<endl<<ctime(&t)<<endl; 
    }
}
这能通过编译?
求解。。
loong0306 2014-06-20
  • 打赏
  • 举报
回复
调用time不好用,求教。

64,639

社区成员

发帖
与我相关
我的任务
社区描述
C++ 语言相关问题讨论,技术干货分享,前沿动态等
c++ 技术论坛(原bbs)
社区管理员
  • C++ 语言社区
  • encoderlee
  • paschen
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
  1. 请不要发布与C++技术无关的贴子
  2. 请不要发布与技术无关的招聘、广告的帖子
  3. 请尽可能的描述清楚你的问题,如果涉及到代码请尽可能的格式化一下

试试用AI创作助手写篇文章吧