Execute CMD commands using C++(使用 C++ 执行 CMD 命令)
问题描述
在我的项目中,我想执行一些 CMD 命令.使用 C++ 执行此操作的语法是什么.
In my project I want to execute some CMD commands. What is the syntax for doing that using C++.
推荐答案
您可以使用名为 system(); 的 C++ 函数执行 Windows 命令提示命令.为了更安全的标准,建议您使用 Windows 特定的 API,例如 ShellExecute 或 ShellExecuteEx.下面是如何使用 system() 函数运行 CMD 命令.
You can execute Windows Command prompt commands using a C++ function called system();. For safer standards you are recommended to use Windows specific API'S like ShellExecute or ShellExecuteEx. Here is how to run CMD command using system() function.
您应该在程序源代码中放置如下所示的 CMD 命令:
You should place the CMD command like shown below in the program source code:
system("CMD_COMMAND");
这是一个在 CMD 中执行 DATE 命令来查找日期的程序:
Here is a program which executes the DATE command in CMD to find the date:
#include <iostream>
using namespace std;
int main() {
system("DATE");
return 0;
}
这篇关于使用 C++ 执行 CMD 命令的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:使用 C++ 执行 CMD 命令
基础教程推荐
- 我应该对 C++ 中的成员变量和函数参数使用相同的名称吗? 2021-01-01
- 为什么 RegOpenKeyEx() 在 Vista 64 位上返回错误代码 2021-01-01
- CString 到 char* 2021-01-01
- 非静态 const 成员,不能使用默认赋值运算符 2022-10-09
- 初始化列表*参数*评估顺序 2021-01-01
- 如果我为无符号变量分配负值会发生什么? 2022-01-01
- 为什么 typeid.name() 使用 GCC 返回奇怪的字符以及如 2022-09-16
- 通过引用传递 C++ 迭代器有什么问题? 2022-01-01
- 为什么派生模板类不能访问基模板类的标识符? 2021-01-01
- GDB 显示调用堆栈上函数地址的当前编译二进制文 2022-09-05
