Answer the question
In order to leave comments, you need to log in
C++ System executing commands with arguments?
Hey! I am writing a program (if I may say so) a C++ compiler .
THE CODE:
#include <iostream>
#include <string>
using namespace std;
int main () {
string test = "test.cpp";
string command = "cl /EHsc " + test;
system(command);
return 0;
}
main.cpp(10): error C2664: "int system(const char *)": невозможно преобразовать аргумент 1 из "std::basic_string<char,std::char_traits<char>,std::allocator<char>>" в "const char *"
C:\Users\User\Desktop\main.cpp(10): note: Для выполнения данного преобразования нет доступного оператора преобразования, определенного пользователем, или вызов оператора невозможен
Answer the question
In order to leave comments, you need to log in
The problem is that you are trying to concatenate with . Also in the function that accepts you put a line from std. You need to call y to get a C-style stringconst char*
std::string
const char*
c_str
std::string
int main(int argc, char** argv)
{
std::string test = "test.cpp";
std::string command = "cl /EHsc " + test;
system(command.c_str());
return 0;
}
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question