g++ - Entering the input values during run-time of a C++ program (./filename.out) -


i want enter user input during run-time of c++ program i.e during ./a.out illustration : ./a.out input1 input2

the c++ program :

program add 2 numbers

#include<iostream> using namespace std;  int main() {     int a, b;     cin >> >> b;     int c = + b;     cout << "the sum of 2 numbers : " << c << "\n"; } 

now please me enter values of , b @ run-time while running output file in linux terminal.

try (dont forget include appropriate headers)

int main(int argc, char** argv) {    if ( argc == 3 ) // command line has 3 arguments, program, arg1 , arg2    {      int sum = atoi(argv[1]) + atoi(argv[2]);      cout<<"the sum of 2 numbers : "<< sum << endl;    }    else    {      cout << "wrong number of arguments, expected 2 numbers" << endl;      cout << "yourprogramname {number1} {number2}" << endl;    } } 

Comments

Popular posts from this blog

django - How can I change user group without delete record -

java - EclipseLink JPA Object is not a known entity type -

java - Need to add SOAP security token -