visual c++ - How to use int argc,char *argv[] outside of main function in c++? -


i having problem when writing codes in c++. used int argc,char *argv[] outside of main function , tells me not defined.
have tried use extern doesn't help. can please me this? thank you!

extern int __argc; extern char **__argv; 

try either setting global variable, or passing values of argc , argv functions.

method 1:

int argc; char **argv;  void some_other_function() {   std::cout <<  argv[0] << "\n"; } int main(int ac, char **av) {   argc = ac;   argv = av;   some_other_function(); } 

method 2:

void some_other_function(int argc, char **argv) {   std::cout <<  argv[0] << "\n"; } int main(int ac, char **av) {   some_other_function(argc, argv); } 

Comments

Popular posts from this blog

blackberry 10 - how to add multiple markers on the google map just by url? -

php - guestbook returning database data to flash -

delphi - Dynamic file type icon -