我想用Visual Studio編譯一個C++軟件。C++:讀取文件時程序卡住了。爲什麼?
要運行我用這個命令行程序:
ABC 0.85 x.txt < x.txt
該軟件是這樣的:
int main(int argc, char ** argv)
{
//main variables
float min_sup = atof(argv[1]); //minimum support
string filename = argv[2]; //input file name
cout << "Hello" << argv << " " << endl;
if(argc < 2)
{
cout << "[Error] Usage: <min> <input file> < <input file>" << endl;
cout << "E.g: ./ABC.exe 0.85 input.txt < input.txt" << endl;
system("PAUSE");
return 1;
}
//checking min_sup value
if(min_sup <= 0 || min_sup >= 1)
{
cout << "[Error] Minimum must be between 0 and 1 exclusively." << endl;
system("PAUSE");
return 1;
}
int in_buf;
while(cin >> in_buf)
{
.....
當我運行的軟件,它會卡在:
while(cin >> in_buf)
你知道什麼問題?它是如何讀取文件的問題?
我在Windows 7 64位上運行代碼。
x.txt的內容會有幫助。 – themel
x.txt是一個很大的文本文件。每行都是一個整數列表。例如,一行可以是:「12 14 15 19 20」。我知道程序在這個時候的第一行卡住了,因爲我使用了調試器,調試器卡在那裏。當我從命令行運行程序時,它也會卡住。 – Phil
我想知道如果問題是由於「<」重定向操作符 – Phil