function - How to create/run a .exe from a program? (C++) -


Is it possible (and if so,) what parameters to write in the program in C ++, then Run that program from other C ++ programs

Ie: I can create a function that adds two numbers:

  int plus (int a, int b) {a + b;}  

Is it possible to do the same thing, instead of a function, a separate C ++ Exe?

Edit: Because a lot of people can not understand my question, I try to say what I want to do.

I have to create a program, call it "p1".

I want this program to get two numbers from the user:

  int x, y; CIN & gt; & Gt; X; CIN & gt; & Gt; Y;  

Now I want to create another program, which takes two numbers, and adds them, there will be a function except for a separate program.

Then I want to get the first program from the program to run the second program with the number of the user. Ie:

  contains # lt; Iostream & gt; using namespace std; Int main () {int x, y; CIN & gt; & Gt; X; CIN & gt; & Gt; Y; (X, y) add; // How do I call a function called "add"? I have to know how to do this with a different program rather than a separate program. Return 0; }  

Edit: I have learned how to use

  (zero) system ("C: \\ program files \\ test.exe ");  

How do I use that to pass arguments, and how can I write a program that can take those arguments? In most OS, you can pass arguments in the system () by separating them:

  System ("someapp.exe 42 24");  

This string is definitely, sprintf or std :: ostringstream or what you may have.

Then you just have your arguments among other programs:

  int main (int argc, char ** argv) {// Important - make sure we have enough logic If (argc! = 3) {// First (zero) argument is always the name of the program, therefore 1 + 2 ARG is needed fprintf (stderr, "wrong number logic \ n"); Return EXIT_FAILURE; } Int a = atoi (argv [1]); Int b = atoi (argv [2]); // do stuff}  

Comments

Popular posts from this blog

python - Overriding the save method in Django ModelForm -

html - CSS autoheight, but fit content to height of div -

qt - How to prevent QAudioInput from automatically boosting the master volume to 100%? -