在c++中如何使用difftime?

来源:百度知道 编辑:UC知道 时间:2024/05/26 04:12:41
这是程序源代码
#include <time.h>
#include <stdio.h>
#include <dos.h>
#include <conio.h>
int main(void)
{
time_t first, second;
clrscr();
first = time(NULL);
delay(2000);
second = time(NULL);
printf("The difference is: %f\ seconds\n",difftime(second,first));
getch();

return 0;
}

以下是错误:
h:\c,c++\新建文件夹\3.cpp(8) : error C2018: unknown character '0xa1'
h:\c,c++\新建文件夹\3.cpp(8) : error C2018: unknown character '0xa1'
h:\c,c++\新建文件夹\3.cpp(8) : error C2018: unknown character '0xa1'
h:\c,c++\新建文件夹\3.cpp(8) : error C2018: unknown character '0xa1'
h:\c,c++\新建文件夹\3.cpp(8) : error C2065: 'clrscr' : undeclared identifier
h:\c,c++\新建文件夹\3.cpp(9) : error C2018: unknown character '0xa1'
h:\c,c++&#

你的那些unknown character '0xa1' 的错误就是因为字符是全角字符
即中文输入法下输入的

可能你输入时用的是中文输入法
或者是从别处拷贝来的代码

c++不能用clrscr,delay

#include <time.h>
#include <stdio.h>
#include <dos.h>
#include <conio.h>
#include <windows.h>

int main(void)
{
time_t first, second;
//clrscr();
system("cls");
first = time(NULL);
//delay(2000);
Sleep(2000);
second = time(NULL);
printf("The difference is: %f seconds\n",difftime(second,first));
getch();

return 0;
}