首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 开发语言 > C++ >

时间延迟函数对比解决思路

2012-02-19 
时间延迟函数对比请看以下代码:#include iostream.h#include conio.h#includetime.h//定义时间延迟

时间延迟函数对比
请看以下代码:

#include <iostream.h>
#include <conio.h>
#include   <time.h>

//定义时间延迟函数
void   Dtime(double   dt)   {
        time_t   current_time;
        time_t   start_time;

        //   得到开始时间
        time(&start_time);
        //延迟处理
        do  
        {
            time(&current_time);
        }  
        while   (difftime(current_time,start_time) <dt);
}

//控制台函数显示
void   cputs_show(int   n)   {
        time_t   current_time;
        char   *timep;
        cputs( "Show   time   with   cputs\n ");

        for(int   i=0;i <5;i++)   {
                time(&current_time);
                timep=ctime(&current_time);
                cputs(timep);
                Dtime(n);
        }
}

//cout对象显示
void   cout_show(int   n)   {
        time_t   current_time;
        char   *timep;
        cout < < "Show   time   with   cout " < <endl;

        for(int   i=0;i <5;i++)   {
                time(&current_time);
                timep=ctime(&current_time);
                cout < <timep;
                Dtime(n);
        }
}

//main()函数的定义
void   main(void)
{
        cputs_show(1);
        cout_show(1);
}


运行后看一下结果,感觉主要区别在于cout与_cputs(),查阅资料后发现_cputs()的说明:
    "These   routines   read   and   write   on   your   console   or   on   the   specified   port.   The   console   I/O   routines   are   not   compatible   with   stream   I/O   or   low-level   I/O   library   routines.   The   console   or   port   does   not   have   to   be   opened   or   closed   before   I/O   is   performed,   so   there   are   no   open   or   close   routines   in   this   category.   In   Windows   NT   and   Windows   95,   the   output   from   these   functions   is   always   directed   to   the   console   and   cannot   be   redirected. "

不是太懂,所以想要请教一下,cout与_cputs()区别,以及上文提到的 "Console   and   Port   I/O ".



[解决办法]
多多指教
-----------------------------------------------

"These routines read and write on your console or on the specified port.


这些是读、写控制台或者指定的端口的函数。

The console I/O routines are not compatible with stream I/O or low-level I/O library routines.
控制台的输入/输出函数,不兼容流的输入/输或者低级的输入/输出类库的出函数。

The console or port does not have to be opened or closed before I/O is performed,
在执行(操作)之前,控制台或者端口,不必打开以及关闭。

so there are no open or close routines in this category.
所以,在这类型的函数中,没有打开和关闭的函数。

In Windows NT and Windows 95,
在Windows NT和Windows95中,

the output from these functions is always directed to the console and cannot be redirected. "
这些函数中的输出,是直接输出到控制台,而不允许转向输出。

热点排行