作者star1327p (sin30t)
看板EE_DSnP
標題[問題] 請問command line 的用法
時間Wed Dec 3 00:37:00 2008
其實我大一修過教授的計程(請見ID對照表),目前大二正在修演算法。
寫programming assignment遇到瓶頸,才知道計程的重要性...
想請問command line的問題:
連第一個cout 都出不來
然後...程式發生錯誤,即將關閉 請問是怎麼一回事?
我command line這樣寫 maxset 12.txt 12out.txt
以下是 code maxset.cpp 前面一部份
int main(int argc, char **argv)
// Can we cancel "int argc"?
{
cout << argv[1]<<" Done." << endl;
system("PAUSE");
/* variables declaration */
int N;
// set the chord set and M to size 500,
// which is the max of the three cases
int chord[500][500];
int M[500][500];
int record[500][500];
/* get the input file */
ifstream inFile(argv[1], ios::in);
if (!inFile)
{
cerr << "File could not be opened." << endl;
system("PAUSE");
return 0;
}
// decide the value of N
if (argv[1] == "12.in")
{N = 6;}
--
※ 發信站: 批踢踢實業坊(ptt.cc)
◆ From: 59.115.181.192
1F:推 timrau:argv[1] == "12.in"是不行的....因為變成在比pointer位置 12/03 00:43
2F:→ timrau:請改為if(!strcmp(argv[1], "12.in")) 12/03 00:43
3F:→ timrau:另一個可能:請把那三個巨大的二維陣列改為static試試 12/03 00:45
4F:→ timrau:可能是stack overflow 12/03 00:45
5F:推 ric2k1:argv[1] == "12.in" 雖然不好, 但是不至於造成 crash 12/03 01:01
6F:→ ric2k1:你用 devC++ 是吧? stack memory overfloat 了... 12/03 01:01
7F:→ ric2k1:改成 static int [][], or double pointer 12/03 01:02
8F:推 ric2k1:用 fixed size array 其實是不好的習慣... 12/03 01:07