+ 2
Command line Arguments in C++
Can somebody please briefly explain me about (int argc , char* argv[]) used in c++. I tried to learn it from some YouTube tutorials but didnât quite get it.
5 Answers
+ 4
int main(int argc, char* argv[]){
cout << argv[1] << endl;
}
----
*compile code*
in the commandline:
yourcode.exe hello
output:
hello
+ 4
Google your IDE and what type of executable it generates. Then you can run the executable the way Cat Sauce said.
+ 3
Yes! This is something that took a while for me to get too. C++ can get compiled on the command line using a compiler program like GCC. When you compile, the output is an executable binary that you can run with arguments. Example:
g++ main.cpp -o exec
g++ is just a way you can run GCC
./exec arg1 arg2
arg1 and arg2 will be the 2nd and 3rd elements in the argv array. The first element is the program name itself
+ 3
Raja Shahvez if you still have trouble, feel free to dm me
+ 3
Cat Sauce I litteraly didnât get it.
can you plz explain with another example