在輸入選項/參數後,如何使用使用argv []的if/then語句?使用if/then語句解析C++中的argv []選項
例如,的a.out -d 1 sample.txt的與的a.out -e 1 sample.txt的。
int main (int argc, char *argv[])
{
ifstream infile(argv[3]);
int c;
int number = 0;
int count = 0;
while (infile.good()) {
if (argv[1] == "-d")
{
c = infile.get();
number = atoi(argv[2]);
if (number == count)
{
cout.put(c);
count = 0;
}
else
count++;
}
if (argv[1] == "-e")
{
cout << "entered -e" << endl; //testing code
}
}//end while
}//end main
可能的重複http://stackoverflow.com/questions/11106062/are-command-line-arguments-some-strings – chill
你的代碼是否給出錯誤? – asheeshr
你能否重申你的問題?你的問題到底是什麼? –