【发布时间】:2012-02-25 06:22:25
【问题描述】:
我正在尝试使用用户的输入作为将传递给 cmd 的参数...
我知道要在我的程序中使用 cmd,我需要使用这个:
system("SayStatic.exe hello world");
但这正是我需要的:
char item[100];
gets(item);
//after getting the input I need to pass it to SayStatic.exe that is the part I dont know
我知道我不能使用 sysytem();为此,但像 spawnl() 或 execl() 之类的其他方法会起作用吗?
【问题讨论】:
-
为什么不能使用
system()? -
我需要参数是一个变量
-
不要永远使用
gets作为输入,这是一个巨大的漏洞,很容易用于缓冲区溢出。无论如何,C++ 程序员应该使用iostream的东西,而不是cstdio的东西。
标签: c++ command-line cmd