使用C ++执行CMD命令 [英] Execute CMD commands using C++

查看:340
本文介绍了使用C ++执行CMD命令的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在我的项目中,我想要执行一些CMD命令。

In my project I want to execute some CMD commands. What is the syntax for doing that using C++.

推荐答案

您可以使用C ++函数执行Windows命令提示符命令 system(); 对于更安全的标准 ,建议您使用Windows特定的API,例如使用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 Use Windows specific APIs like ShellExecute or ShellExecuteEx. Here is how to run CMD command using system() function.

在程序源代码中:

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命令的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆