【发布时间】:2012-11-28 17:15:19
【问题描述】:
根据输入的选项/参数,您将如何使用使用 argv[] 的 if/then 语句?
例如,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
【问题讨论】:
-
你的代码有错误吗?
-
能否请您重述您的问题?你的问题到底是什么?
-
@AshRj - 没有错误,但是当我运行 a.out 时,-d 和 -e 没有任何反应。
-
@harman2012 这是因为程序没有传递给 while() 主体
标签: c++ if-statement argv