作者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