【发布时间】:2017-06-29 06:17:47
【问题描述】:
我想输出时间并循环它,这样时间会不断更新,而不会一次又一次地输出同一行,所以我认为 id 使用马车覆盖该行,但它似乎不起作用,我没有不知道为什么,是不是和Xcode有关??我之前已经阅读过有关 \r 的堆栈溢出的其他帖子,并尝试将答案调整为我的代码,但似乎没有一个解决方案有效,也与 ios/Xcode 无关。我还假设问题可能与 Xcode 控制台有关,因为它不是终端(但我不确定)
#include <iostream>
#include <time.h>
using namespace std;
int main(int argc, const char * argv[]) {
//Loop Forever
for(;;){
time_t rawtime;
struct tm * timeinfo;
time ( &rawtime );
timeinfo = localtime ( &rawtime );
cout << "The current date/time is: " << asctime(timeinfo) << "\r";
}
return 0;
}
output:
The current date/time is: Fri Feb 10 17:20:43 2017
The current date/time is: Fri Feb 10 17:20:43 2017
The current date/time is: Fri Feb 10 17:20:43 2017
The current date/time is: Fri Feb 10 17:20:43 2017
The current date/time is: Fri Feb 10 17:20:43 2017
The current date/time is: Fri Feb 10 17:20:43 2017
The current date/time is: Fri Feb 10 17:20:43 2017
The current date/time is: Fri Feb 10 17:20:43 2017
The current date/time is: Fri Feb 10 17:20:43 2017
The current date/time is: Fri Feb 10 17:20:43 2017
The current date/time is: Fri Feb 10 17:20:43 2017
The current date/time is: Fri Feb 10 17:20:43 2017
The current date/time is: Fri Feb 10 17:20:43 2017
The current date/time is: Fri Feb 10 17:20:43 2017
The current date/time is: Fri Feb 10 17:20:43 2017
The current date/time is: Fri Feb 10 17:20:43 2017
The current date/time is: Fri Feb 10 17:20:43 2017
The current date/time is: Fri Feb 10 17:20:43 2017
【问题讨论】:
-
你想做什么?您是否要在新行上打印每个?还是您要清除当前行并用更新的时间覆盖该行?
-
对不起,我应该更具体,我正在尝试清除当前行并覆盖
-
最好将程序的输出直接复制粘贴到问题中,而不是将图像上传到输出中。我建议您编辑问题以这样做。
-
我已经编辑了,这样更好吗?
-
将输出格式化为代码