cygwin c ++程序首先在cygwin终端中以单独的cmd运行

时间:2014-09-05 03:02:53

标签: c++ windows cygwin

我刚刚安装了cygwin并且已经习惯了它,我相信它使用终端模拟器。

无论如何,当我运行一个简单的cpp程序时,我编写并编译它会生成一个新的cmd窗口并运行程序,当我关闭程序再次在mintty终端运行时......有没有办法防止这种情况? / p>

编辑: 我没有触及cygwin安装,但我确实通过cygwin设置安装了g ++。这是我试图运行的程序:

#include <iostream>
#include <string>
#include <vector>

using namespace std;

void Adder(){
    // Variables for state
    bool terminated = false; //Whether double zeroes have been entered
    int consecZeroes = 0; //Number of consecutive zeroes seen.
    int val;
    int subtotal = 0;
    int total = 0;

    // Loop and receive user input
    while(!terminated){
        cout << ">";
        cin >> val;
        // Check to make sure the val is a valid number
        if(!cin){
            cout << "Incorrect entry." << endl;
            terminated = true;
        }else{
            // Double zeroes: print total and exit
            if(val == 0 && consecZeroes == 1){
                cout << "Total " << total << endl;
                terminated = true;
            }
            // Single zero: print subtotal and reset to 0
            else if(val == 0 && consecZeroes == 0){
                cout << "Subtotal " << subtotal << endl;
                subtotal = 0;
                consecZeroes++;
            }
            // Add to subtotal
            else if(val != 0){
                consecZeroes = 0;
                subtotal = subtotal + val;
                total = total + val;
            }
            // Just in case
            else{
                cout << "Something went wrong." << endl;
            }
        }
    }
}

int main(){
    Adder();

    return 0;
}

我使用命令g ++ -g -Wall -o out file.cpp通过cygwin编译它。这产生了out.exe。使用命令运行此命令./out.exe会生成一个运行该程序的cmd控制台,当我退出该程序时,程序将在mintty终端重新启动。

0 个答案:

没有答案