簡體   English   中英

該程序無法在DOS模式下運行

[英]This program cannot be run in DOS mode

我正在嘗試一個程序並使用GCC編譯和運行它,但它會拋出錯誤,它無法在dos模式下運行。 這是我的代碼

#include<iostream>
#include<fstream>
using namespace std;
int main(int argc, char *argv[]) 
{ 
    ifstream is; 
    is.open("text1.txt",ios::binary);
    ofstream outfile;
    outfile.open("text2.txt",ios::binary);
    char ch; 
    while (is.get(ch)) 
    { 
        outfile.put(ch);
        cout << ch;  //this shows
    }
    is.close();
    outfile.close();
    getchar();
    return 0; 
}

但是這段代碼在Visual Studio中運行得非常好。 有什么建議么?

我假設有一個gcc編譯選項可以作為控制台命令運行。 請參閱-mconsolehttp-mconsole

如果你想做更多的跨平台友好,你可以刪除線

#include<conio.h>

並為getchar()更改getch()

編輯:所以它看起來像這樣:

 #include<fstream>
 using namespace std;
 int main(int argc, char *argv[])
 {
     ifstream is;
     is.open("text1.txt",ios::binary);
     ofstream outfile;
     outfile.open("text2.txt",ios::binary);
     char ch;
     while (is.get(ch))
     {
         outfile.put(ch);
         cout << ch;  //this shows
     }
     is.close();
     outfile.close();
     getchar();
     return 0;
 } 

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM