注册 登录
编程论坛 C++教室

无限循环

欢乐人生0 发布于 2013-05-28 13:44, 680 次点击
1. 在Windows操作系统中,创建控制台程序child,程序无限循环输出如下格式的文字:
“The child is talking at [system time]”
其中的system time是程序获取到的系统时间
提示:使用cout<<ctime(&t1)<<endl;可以输出当前的系统时间(C++);
真的是想不出怎么做。。。
3 回复
#2
apull2013-05-28 14:38
程序代码:
#include <iostream>
#include <windows.h>
#include <ctime>

using namespace std;

int main() {
    char tt[30],*p;
    p=tt;
    time_t t;
    while(1)   
    {
        t=time(&t);
        p=ctime(&t);
        p[strlen(p)-1]='\0';
        system("cls");
        cout << "The child is talking at [" << p << "]" << endl;
        Sleep(1000);
    }
   
    return 0;
}
#3
欢乐人生02013-05-28 23:01
谢谢
#4
欢乐人生02013-05-28 23:05
2. 在Windows操作系统中,创建另外一个控制台程序parent,这个程序再创建一个进程去执行child程序, 同时parent进程无限循环输入如下格式的文字
“The parent is talking at [system time]”
其中的system time是程序获取到的系统时间
最后请解释输出结果。
能帮我再看看这道题吗?谢谢
1