小编Abi*_*rer的帖子

保持屏幕畅通

在我的C++书籍示例中,我使用系统("暂停")来保持屏幕打开,这是我从操作系统中学到的仅用于作业.现在我的书中有一个例子,它使用exit(),依赖于true或false,我的屏幕消失了.如果我取出exit()程序一直在计算(这就是作者放在exit()中的原因)但是如何解决这个问题?我正在使用Microsoft VS C++ Express 2012 for Windows Desktop.

//prime.cpp
// demonstrates IF statement with prime numbers
#include <iostream>
using namespace std;
#include <process.h>        //for exit()

int main()
    {
        unsigned long n,j;
        cout << "Enter a number:  ";
        cin >>n;                    //get number to test
        for (j=2; j<= n/2; j++)     //divide by integer from
            if(n%j==0)              //2 on up; if remainder is 0,
            {                       //it's divisible by j

            cout <<"It's not prime; divisible by " <<j<<endl;
            exit (0);               //exit from program
            }
        cout …
Run Code Online (Sandbox Code Playgroud)

c++ if-statement exit

1
推荐指数
1
解决办法
227
查看次数

标签 统计

c++ ×1

exit ×1

if-statement ×1