debug with argv | SoloLearn: Learn to code for FREE!

0

debug with argv

i'm just testing to run prog using parameters, but why i got error when debugging? https://imgur.com/76bWTgP this is my code: #include <iostream> int main (int argc, char * argv []) { if (argc > 0) { std::cout << *argv[1] << std::endl; } std::cin.ignore(std::numeric_limits<int>::max(), '\n'); std::cout << "press ENTER to close program."; std::cin.get(); return 0; }

c++

7/4/2020 8:08:06 PM

Chipp

8 Answers

New Answer

+1

numeric_limits<> is defined in the limits library. It won't run correctly on SL compiler, you need to provide arguments to the program. Run it through the terminal and give arguments to it, it will work fine then.

0

You don't need to dereferece argv when using [ ], the operator return first character as char* and operator<< will follow it until NUL char: #include <iostream> int main (int argc, char * argv []) { if (argc > 0) { std::cout << argv[1] << std::endl; } std::cin.ignore(std::numeric_limits<int>::max(), '\n'); std::cout << "press ENTER to close program."; std::cin.get(); return 0; }

0

still error

0

How do you run the program ?

0

debug it on VS

0

limits library was not included. #include <iostream> #include <limits> int main (int argc, char * argv []) { if (argc > 0) { std::cout << argv[1] << std::endl; } std::cin.ignore(std::numeric_limits<int>::max(), '\n'); std::cout << "press ENTER to close program."; std::cin.get(); return 0; }

0

what's <limits> has anything to do with this..? it's still error https://imgur.com/a/w2VIhQ8

0

ok, no one could spot it, apparently... it's bcoz of argc... argv should be displayed when argc > 1...!