c++ main function, argc value is weird if command-line arguments contain * -
a simple piece of c++ code this:
int main(int argc, char **argv){ std::cout << "argc: " << argc << std::endl; }
compiled g++ -o hello hello.cpp
- when run
./hello u
, outputargc: 2
; - when run
./hello u +
, outputargc: 3
; - when run
./hello u *
, outputargc: 26
, why26
?
shell expansion. *
expanded shell files in current directory, of there appear 24, , passes them individual arguments program.
since looks call unix shell, use
./hello u \*
or
./hello u '*'
Comments
Post a Comment