Answer the question
In order to leave comments, you need to log in
How to insert string value as function argument?
Greetings to all, there is a need to insert a string value as a function argument, what should I do? Suppose there is a code with a system function that received an argument in the form of a command to change the color (1 character - console, 2 - text).
#include <iostream>
#include <cstdlib>
using namespace std;
int main()
{
system("color FC");
return 0;
}
Answer the question
In order to leave comments, you need to log in
1. Collect the body of the command in a string variable or string buffer, escaping the parameters if necessary.
2. If it's a wrapped string, convert it to const char* and off you go.
std::string command;
char data1 = 'F';
char data2 = 'C';
command = std::string("color ") + data1 + data2;
system(command.c_str());
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question