aman
aman

Reputation: 393

Why is the error E0413 occurring in system() in C++?

#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;
}

I do not understand to why I'm getting the error 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 at the system(). Please Help

Upvotes: 0

Views: 2739

Answers (1)

Tyker
Tyker

Reputation: 3047

you have this error because you code mixes string and const char* (wich isn't your fault) and there can only be implicit convertion from const char* to string but not the other way so you need to make the convertion using std::string::c_str

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

Upvotes: 5

Related Questions