Robert
Robert

Reputation: 233

How to properly handle const char* in c++

bool check(const char* pass); 
  1. Does const mean that I cannot modify char* inside the function?

  2. Does char* c has any function like contains(char c) which checks if the char is inside char*?

  3. How to get to 4th character in the char*?

  4. Is there any function which gives the length of that char*. Beside checking where is '\0'?

Upvotes: 1

Views: 3308

Answers (1)

Luchian Grigore
Luchian Grigore

Reputation: 258548

Use std::string instead.

  1. No, it means you can't modify the chars.

  2. char* is a pointer, it doesn't have any functions. You can look up strchr.

  3. pass[3]

  4. strlen, but it checks for '\0' internally.

Upvotes: 8

Related Questions