D
D
Dmitry Popov2018-11-08 17:23:09
C++ / C#
Dmitry Popov, 2018-11-08 17:23:09

Is it possible to use variables in the system function?

For example, there is a code:

int main(void)
{
    int i = 1;
    system("echo $i")
    return 0;
}

However, echo does not treat the value of i as 1, which is what is required, but as an empty string. How, then, to pass variables to the system function?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
S
Stanislav Makarov, 2018-11-08
@DigitalLev

Sit down and learn C++, this is not PHP for you.
Use std::to_string(i) and concatenate the string you need, or do a replacement on the original string with std::string's replace method.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question