gpt4 book ai didi

c++ - 为什么C++中的system()会出现E0413错误?

转载 作者:行者123 更新时间:2023-11-27 22:39:33 24 4
gpt4 key购买 nike

#include <iostream>
#include <windows.h>
#include <list>
#include <string>

using namespace std;

int main()
{
string content = "video.mp4";
//error occurring on the line beneath
system("cd C:\\Users\\amans\\Documents && " + content);
return 0;
}

我不明白为什么我会收到错误 E0413 = no suitable conversion function from "std::basic_string<char, std::char_traits<char>, std::allocator<char>>" to "const char *" exists media_maker c : \Users\amans\Documents\code\maker.cpp 50在系统()。请帮忙

最佳答案

你有这个错误是因为你的代码混合了 string 和 const char*(这不是你的错)并且只能从 const char* 到 string 的隐式转换而不是其他方式所以你需要使用 std::string::c_str 进行转换

system(("cd C:\\Users\\amans\\Documents && " + content).c_str());

关于c++ - 为什么C++中的system()会出现E0413错误?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50151808/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com