如何将参数从c++程序传递给cmd
How to pass an argument from a c++ program to cmd?
我正在尝试使用用户的输入作为将传递给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()的方法会奏效吗?
首先,不要使用gets()
。它不应该包含在标准库中,因为比字符串长的输入将覆盖堆栈内存并导致未定义的行为(可能是某种崩溃)。如果您使用的是C字符串,fgets()
是一个可以接受的替代品。
你可以使用这样的C++字符串:
std::string line;
std::getline(std::cin, line);
system(("SayStatic.exe " + line).c_str());
相关文章:
- 在由Sublime文本3编译后在cmd上显示Java程序输出
- 如何在使用Makefile构建后在cmd中运行该程序?
- 为什么下面的Hello World程序在PowerShell上没有显示任何输出?同一程序在CMD上显示正确的输出
- 使用 system() 函数在C++程序中运行 cmd 命令
- cmd.exe与Powershell中C++程序的不同执行时间
- 从Visual Studio 2017运行MPI应用程序,每个进程在不同的cmd窗口中
- 如何将我的程序转换为.dll文件并使用rundll32.exe在cmd中运行它?
- CPP 程序二查找两个给定日期之间的天数,conol CMD
- 如何在Powershell中运行C++程序,就像CMD一样?
- CMD:程序.exe 1< "A:/input.txt"产生无输出
- 在 turbo c++ 中使用 TCC 从 cmd 编译C++程序
- 在Qt小部件应用程序中显示cmd终端
- 如何在C++程序中打开一个新的cmd.exe并获取其句柄
- C++使程序cmd友好
- 在cmd中运行程序时出现问题
- 程序在cmd中工作,在cygwin中立即以状态127退出,在emacs shell中没有输出
- C 如何通过同一MFC应用程序通过System Command打开Excel文件后关闭CMD EXE
- 为什么这个C++程序的输出在cmd中产生了巨大的混乱
- 使用 cmd.exe 显示或捕获完整的程序输出
- 试图学习威纳皮.制作了第一个程序,必须向我显示一个窗口.CMD显示,但没有窗口