69,371
社区成员
发帖
与我相关
我的任务
分享
while(1)
{
dosomething(); //做一些事情
scanf(); //输入一些东西
}
#include <Windows.h>
#include <iostream>
using namespace std;
DWORD WINAPI getCin(void*param)
{
cout << "getcin...\n";
while(cin.peek() != EOF);
return 1;
}
void test()
{
cout << "check buffer...\n";
SYSTEMTIME x = {};
GetSystemTime(&x);
long long start = x.wSecond;
CreateThread(NULL, 0, getCin, NULL, 0, 0);
string y;
while(true)
{
GetSystemTime(&x);
if (x.wSecond >= start + 20)
{
start += 20;
cout << "do something...\n";
}
if (cin.rdbuf()->in_avail() != 0)
{
std::getline(cin, y);
cout << "your input: " << y << endl;
}
}
}
#include <windows.h>
#include <process.h>
#include <string.h>
#include <stdio.h>
void CheckKey(void *dum);
void doSomething(){printf("doSomething\n");}
char str[1000];
int repeat = 1;
int main()
{
while(repeat)
{
doSomething();
_beginthread(CheckKey,0,NULL);
Sleep(5000L);
}
return 0;
}
void CheckKey(void *dum )
{
scanf("%s",str);
if(!strcmp(str,"#"))
repeat = 0;
else
printf("Input Message %s \n",str);
_endthread();
}
#include<stdio.h>
#include<windows.h>
void doSomeThing(){printf("Do Something\n");}
int main()
{
int iTickTrigger = 0;
int iTickCount;
int delay = 1000*5;
while(1)
{
iTickCount= GetTickCount();
if(iTickCount>iTickTrigger)
{
iTickTrigger = GetTickCount()+delay;
doSomeThing();
}
}
return 0;
}
#include <time.h>
int main(void)
{
time_t rawtime;
time(&rawtime);
return 0;
}