【问题标题】:Iterate through multiple command line Arugments遍历多个命令行参数
【发布时间】:2014-06-05 02:55:22
【问题描述】:

我有一个 c++ 程序需要这样的命令行参数

./Program textfile.txt argu1 10 

然后它使用 cout 在命令行上给出一个输出。

但是,有没有一种简单的输入方法

./Program textfile.txt argu1 10 
./Program textfile.txt argu1 20 
./Program textfile.txt argu1 30 

我需要文本输出文件,因为我需要运行其中的 100 个。

我宁愿不手动...

【问题讨论】:

标签: c++ command-line-arguments argument-passing


【解决方案1】:

如果你在bash shell 中工作,你可以使用:

for i in $(seq 10 10 1000)
do
  ./Program textfile.txt $i >> ouitput.txt
done

【讨论】:

  • 并输出到文件,使用./Program textfile.txt $i >> ./output.txt 将每个结果附加到./output.txt 确保在最后一个cout 的末尾使用endl,以便结果结束输出文件上的不同行。
  • @vsoftco 感谢您的提示。答案已更新。
猜你喜欢
  • 1970-01-01
  • 2015-11-30
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2023-03-17
  • 2023-01-26
  • 2012-11-05
相关资源
最近更新 更多