Search
 
SCRIPT & CODE EXAMPLE
 

CPP

if argv == string

int main(int argc, char * argv[]) {

  if (argv[1] == "yes"); // Wrong, compares two pointers
  if (strcmp(argv[1], "yes") == 0); // This compares what the pointers point to
  if (std::string(argv[1]) == "yes"); // Works fine
  if (argv[1] == std::string("yes")); // Works fine

  // Easy-mode    
  std::vector<std::string> args(argv, argv+argc);
  for (size_t i = 1; i < args.size(); ++i) {
      if (args[i] == "yes") {
          // do something
      }
  }

}
Comment

PREVIOUS NEXT
Code Example
Cpp :: how to write int variable c++ 
Cpp :: how to make loop in c++ 
Cpp :: what library is rand in c++ 
Cpp :: set iterator 
Cpp :: what was the piep piper app 
Cpp :: find vector size in c++ 
Cpp :: sliding window c++ 
Cpp :: how to use for c++ 
Cpp :: move elements from vector to unordered_set 
Cpp :: cout stack in c++ 
Cpp :: flag of georgia 
Cpp :: how to extract a folder using python 
Cpp :: c++ classes 
Cpp :: how to run cpp using gcc vscode 
Cpp :: #define in cpp 
Cpp :: cpp vector structure 
Cpp :: how to make a pointer point to a the last value in an array 
Cpp :: c++ class constructor variable arguments 
Cpp :: nth fibonacci number 
Cpp :: initialisation of a c++ variable 
Cpp :: floyd algorithm 
Cpp :: visual studio code terminal keeps closing c++ 
Cpp :: rc.local not running centos 6 
Cpp :: Restart the computer in c++ after the default time (30) seconds. (Windows) 
Cpp :: arduino bleutooth module hc-05 with led 
Cpp :: Minimizing the dot product codechef in c++ 
Cpp :: initalising array c++ 
Cpp :: . Shell sort in c++ 
Cpp :: function param pointer to struct prototype in c 
Cpp :: Operatore ternario c++ 
ADD CONTENT
Topic
Content
Source link
Name
2+4 =