+ 2

Can you pass an argument to the main function??

main function in c++ is the starting point of program exectution

12th May 2019, 11:02 AM
Muhammad Kaleem Ullah
Muhammad Kaleem Ullah - avatar
7 odpowiedzi
+ 3
In the playground you cannot. If you start you program via a command prompt you would do something like this MyProgram.exe first With "first" being the first argument. In visual studio there is setting to add arguments
12th May 2019, 11:14 AM
sneeze
sneeze - avatar
+ 3
Yes this is possible if you use main(int argc, char* argv[]) in your code. Say your file is named "foo.cpp" Then, after compiling, you can call it in your console with additional parameters like ./foo test1 test2 Then argc is 3 and argv[0] : ./foo argv[1]: test1 argv[2]: test2 But I'm afraid you can't do this in Sololearn
12th May 2019, 11:16 AM
Matthias
Matthias - avatar
+ 2
Tap the { } on the menu bar. It is a place to code online in the Sololearn app or website. How do you use Sololearn ? Phone or web ? What ide do you use ?
12th May 2019, 11:23 AM
sneeze
sneeze - avatar
+ 2
Muhammad Kaleem Ullah Cool. Looks good IDE. You definitly can add command line arguments in there using the method of swim
12th May 2019, 11:31 AM
sneeze
sneeze - avatar
+ 1
sneeze i used turbo c++ and dev and heard turbo is more reliable
12th May 2019, 11:25 AM
Muhammad Kaleem Ullah
Muhammad Kaleem Ullah - avatar
0
Muhammad Kaleem Ullah Do you mean Sololearn playground or visual studio ?
12th May 2019, 11:19 AM
sneeze
sneeze - avatar
0
What's sololearn Playground
12th May 2019, 11:20 AM
Muhammad Kaleem Ullah
Muhammad Kaleem Ullah - avatar