単純なリンクを表示して時計のC++とLinux
質問
私はC++を用いたLinuxで作成標準GCC.私のプログラムIを追加したい単純なクロックを示すHH:MM:SS.何のための最も簡単な方法はない。
解決
良い方法を使用することです localtimeのの
他のヒント
私の間に合わせと-ソリューション:
// file now.cc
#include <iostream>
#include <iomanip>
#include <ctime>
using namespace std;
int main()
{
time_t ct = time(0);
struct tm* currtime = localtime(&ct);
cout << setfill('0') << setw(2) << currtime->tm_hour << ":"
<< setw(2) << currtime->tm_min << ":"
<< setw(2) << currtime->tm_sec << endl;
return 0;
}
これはまた、(おそらくたい)ゼロパディングを行います。
#include<stdio.h>
#include<stdlib.h>
#include<time.h>
void delay(unsigned int mseconds)
{
clock_t goal = mseconds + clock();
while (goal > clock());
}
int main()
{
time_t myTime;
while(1)
{
time(&myTime);
printf("%s", asctime(gmtime(&myTime)));
delay(1000);
system("cls");
}
return 0;
}
の最も簡単なの方法はありますか?
system("date +%T");
あなたのgetTimeStamp()
を見てくださいあなたが望む任意の形式にこれを調整することができます。
所属していません StackOverflow