关于转义字符"\r"

来源:互联网 发布:淘宝刷真实流量软件 编辑:程序博客网 时间:2024/06/06 00:06

转义字符"\r"的作用是把光标移到当前的行首,而转义字符"\n"是把光标下一行首。


我们来做一个简单的应用,利用转义字符"\r"动态地在终端显示时间。


#include <iostream>#include <string.h>#include <stdio.h>#include <windows.h>#include <time.h>using namespace std;int main(){time_t t;    char date[35];while(1) {       t = time(NULL);   strcpy(date,ctime(&t));   int len = strlen(date);   date[len-1] = 0;   printf("\r%s",date);   Sleep(500);}return 0; }

上面的char *ctime(const time_t *t);函数的作用是把真实的时间转化为字符串形式。