Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 214879
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 11, 20262026-05-11T18:25:00+00:00 2026-05-11T18:25:00+00:00

Is it possible (and if so, how) to write a program in C++ that

  • 0

Is it possible (and if so, how) to write a program in C++ that takes parameters, then run that program from another C++ program.

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

int add(int a,int b){return a+b;}

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

EDIT: Since a lot of people don’t understand my question, I’ll try to say exactly what I want to know how to do.

I want to have a program, lets call it “p1”.

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

int x,y;
cin>>x;
cin>>y;

Now I want to create another program, that takes two numbers, and adds them, the same way a function would, except a seperate program.

Then I want to run the second program from the first program with the numbers it got from the user. Ie:

#include<iostream>
using namespace std;
int main()
{
     int x,y;
     cin>>x;
     cin>>y;
     add(x,y); //this is how I would call a function named "add".  I want to know how to do that with a separate program instead of just a separate function.
     return 0;
}

EDIT: I figured out how to use

(void)system("C:\\Program Files\\test.exe");

How would I use that to pass arguments, and how could I write a program that takes those arguments?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-11T18:25:00+00:00Added an answer on May 11, 2026 at 6:25 pm

    On most OSes, you can pass arguments in system() by space-seperating them:

    system("someapp.exe 42 24");
    

    This string, of course, can be built up by sprintf or std::ostringstream or what have you.

    Then you just need to process your arguments in the other program:

    int main(int argc, char **argv) {
      // important - make sure we have enough args
      if (argc != 3) { // first (zeroth) argument is always the program name, so 1+2 args is needed
        fprintf(stderr, "Wrong number of arguments\n");
        return EXIT_FAILURE;
      }
      int a = atoi(argv[1]);
      int b = atoi(argv[2]);
      // do stuff
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Ask A Question

Stats

  • Questions 280k
  • Answers 281k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer var fade = $('img:first', this); This will select the first… May 13, 2026 at 3:45 pm
  • Editorial Team
    Editorial Team added an answer From man 3 getaddrinfo, struct addrinfo { int ai_flags; int… May 13, 2026 at 3:44 pm
  • Editorial Team
    Editorial Team added an answer def method_missing(name, *args, &blk) if args.empty? && blk.nil? && @attributes.has_key?(name)… May 13, 2026 at 3:44 pm

Related Questions

Is it possible and if so, how can I do it, to select all
Is it possible, in a script executed in MS SQL Server 2005, to copy
I am trying to write an Audit Log method that will log all changes
One of my coworkers needs a piece of data from a 3rd party website.

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.