if argv 3d 3d string

Solutions on MaxInterview for if argv 3d 3d string by the best coders in the world

showing results for - "if argv 3d 3d string"
Aksel
07 Jan 2020
1int main(int argc, char * argv[]) {
2
3  if (argv[1] == "yes"); // Wrong, compares two pointers
4  if (strcmp(argv[1], "yes") == 0); // This compares what the pointers point to
5  if (std::string(argv[1]) == "yes"); // Works fine
6  if (argv[1] == std::string("yes")); // Works fine
7
8  // Easy-mode    
9  std::vector<std::string> args(argv, argv+argc);
10  for (size_t i = 1; i < args.size(); ++i) {
11      if (args[i] == "yes") {
12          // do something
13      }
14  }
15
16}
similar questions
c 2b 2b argvva arg