debug with argv | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
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; }

4th Jul 2020, 8:08 PM
Chipp
Chipp - avatar
8 Answers
+ 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.
5th Jul 2020, 10:09 AM
blACk sh4d0w
blACk sh4d0w - avatar
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; }
4th Jul 2020, 8:19 PM
قاسم رمضانی
قاسم رمضانی - avatar
0
still error
4th Jul 2020, 8:24 PM
Chipp
Chipp - avatar
0
How do you run the program ?
4th Jul 2020, 8:26 PM
قاسم رمضانی
قاسم رمضانی - avatar
0
debug it on VS
4th Jul 2020, 9:51 PM
Chipp
Chipp - avatar
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; }
4th Jul 2020, 10:29 PM
blACk sh4d0w
blACk sh4d0w - avatar
0
what's <limits> has anything to do with this..? it's still error https://imgur.com/a/w2VIhQ8
5th Jul 2020, 4:27 AM
Chipp
Chipp - avatar
0
ok, no one could spot it, apparently... it's bcoz of argc... argv should be displayed when argc > 1...!
10th Jul 2020, 7:32 PM
Chipp
Chipp - avatar