C++中怎么将运行中的程序暂停并据中间结果是否合符要求决定是否保存运算结果到文本文件等中
C++中如何将运行中的程序暂停并据中间结果是否合符要求决定是否保存运算结果到文本文件等中
一个需要很长时间的计算,我希望通过点击暂停看一下中间计算结果是否符合要求?如果不合要求就点击继续,再接着计算下去;如果合乎要求就点停止,并点保存结果到文本文件。如:计算1+1/2+1/3+…..+1/n+……
要求用VC6.0设计界面完成。
------解决方案--------------------
------解决方案--------------------
既然有中间结果,说明是一步一步进行的。
如果每步消耗时间比较少,那么若干步输出一次中间结果即可。
如果每步消耗时间比较长,那没每步输出中间结果即可。
UI做的话,无非是消息,定时器,线程
------解决方案--------------------
Alphabetical List of MFC Samples
Sample Illustrations
ACDUAL Demonstrates how to add dual interface support to an MFC-based Automation server.
AUTOCLIK Tutorial example illustrating Automation features in Visual C++ Tutorials.
AUTODRIV A simple Automation client application that drives the AUTOCLIK tutorial sample application.
BINDENRL Databound controls in a dialog-based application with property pages.
BINDSCRB Illustration of the use of new COM interfaces to components currently supported by the Microsoft Office suite of products.
CALCDRIV Automation client.
CATALOG Illustration of direct calls to ODBC functions in general, and the ODBC functions SQLTables and SQLColumns in particular.
CATALOG2 Illustration of direct calls to ODBC functions in general using Windows Common Controls.
CHATSRVR Discussion server application for CHATTER.
CHATTER Client application that uses Windows Sockets.
CHKBOOK Record-based (nonserialized) document.
CIRC Tutorial sample that teaches you how to create a simple ActiveX control called Circle.
CMNCTRL1 Demonstrates how to create and change the styles of Windows Common Controls using MFC classes (Part 1).
CMNCTRL2 Demonstrates how to create and change the styles of Windows Common Controls using MFC classes (Part 2).
COLLECT MFC C++ template-based collection classes, and standard prebuilt collection classes.
CONTAINER Tutorial example illustrating ActiveX Visual Editing container features in Visual C++ Tutorials.
COUNTER Using an ISAPI DLL to send image data (rather than HTML data) back to a Web browser.
CTRLBARS Custom toolbar and status bar, dialog bar, and floating palette.
CTRLTEST Owner-draw list box and menu, custom control, bitmap button, spin control.
CUBE OpenGL application using MFC device contexts along with OpenGL's resource contexts.
DAOCTL DAO database class functionality and ActiveX controls let you examine a database.
DAOENROL Based on ENROLL, but migrated to the DAO database classes. Also serves as Step 4 of the DaoEnrol tutorial.
一个需要很长时间的计算,我希望通过点击暂停看一下中间计算结果是否符合要求?如果不合要求就点击继续,再接着计算下去;如果合乎要求就点停止,并点保存结果到文本文件。如:计算1+1/2+1/3+…..+1/n+……
要求用VC6.0设计界面完成。
------解决方案--------------------
#include <stdio.h>
#include <conio.h>
#include <windows.h>
int main() {
int i,k;
FILE *f;
for (i=0;i<1000000;i++) {
if (i%10==0) {
cprintf("\r%08d ",i);
}
Sleep(100);
if (kbhit()) {
k=getch();
cprintf("\r%08d c-continue s-stop&save",i);
k=getch();
if (k=='s') {
f=fopen("result.txt","w");
fprintf(f,"%08d\n",i);
fclose(f);
cprintf("\rSave to result.txt \r\n");
break;
}
}
}
return 0;
}
------解决方案--------------------
既然有中间结果,说明是一步一步进行的。
如果每步消耗时间比较少,那么若干步输出一次中间结果即可。
如果每步消耗时间比较长,那没每步输出中间结果即可。
UI做的话,无非是消息,定时器,线程
------解决方案--------------------
Alphabetical List of MFC Samples
Sample Illustrations
ACDUAL Demonstrates how to add dual interface support to an MFC-based Automation server.
AUTOCLIK Tutorial example illustrating Automation features in Visual C++ Tutorials.
AUTODRIV A simple Automation client application that drives the AUTOCLIK tutorial sample application.
BINDENRL Databound controls in a dialog-based application with property pages.
BINDSCRB Illustration of the use of new COM interfaces to components currently supported by the Microsoft Office suite of products.
CALCDRIV Automation client.
CATALOG Illustration of direct calls to ODBC functions in general, and the ODBC functions SQLTables and SQLColumns in particular.
CATALOG2 Illustration of direct calls to ODBC functions in general using Windows Common Controls.
CHATSRVR Discussion server application for CHATTER.
CHATTER Client application that uses Windows Sockets.
CHKBOOK Record-based (nonserialized) document.
CIRC Tutorial sample that teaches you how to create a simple ActiveX control called Circle.
CMNCTRL1 Demonstrates how to create and change the styles of Windows Common Controls using MFC classes (Part 1).
CMNCTRL2 Demonstrates how to create and change the styles of Windows Common Controls using MFC classes (Part 2).
COLLECT MFC C++ template-based collection classes, and standard prebuilt collection classes.
CONTAINER Tutorial example illustrating ActiveX Visual Editing container features in Visual C++ Tutorials.
COUNTER Using an ISAPI DLL to send image data (rather than HTML data) back to a Web browser.
CTRLBARS Custom toolbar and status bar, dialog bar, and floating palette.
CTRLTEST Owner-draw list box and menu, custom control, bitmap button, spin control.
CUBE OpenGL application using MFC device contexts along with OpenGL's resource contexts.
DAOCTL DAO database class functionality and ActiveX controls let you examine a database.
DAOENROL Based on ENROLL, but migrated to the DAO database classes. Also serves as Step 4 of the DaoEnrol tutorial.