Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
我如何能够与 .DAT 文件和输入一起执行我的 C++ 程序?
例如: ./program.exe file.dat 5
./program.exe file.dat 5
file.dat 中的多个命令行示例:
addpeer 12130 removepeer 13820
在 C++ 中,您使用 main 函数int main(int argc, char *argv[]),argc 包含“参数计数”,即参数的数量,而 argv 是一个向量,其中包含您在调用程序时提供的参数。在你的情况下,它将包含“file.dat”和 5。一旦你有了这个,你就可以用你的程序解析你的文件并用它做你想做的事。
int main(int argc, char *argv[])