Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to convert a char* pointer into a C++ string?

Tags:

People also ask

Is char * a string?

char is a primitive data type whereas String is a class in java. char represents a single character whereas String can have zero or more characters. So String is an array of chars. We define char in java program using single quote (') whereas we can define String in Java using double quotes (").

Can a char pointer point to a string?

We can create a character pointer to string in C that points to the starting address of the character array. This pointer will point to the starting address of the string, that is the first character of the string, and we can dereference the pointer to access the value of the string.

What char * means in C?

char* means a pointer to a character. In C strings are an array of characters terminated by the null character.

Is char * a pointer?

Now, let's start with the char* piece. This is a pointer to a char. It is not necessarily pointing to the beginning or middle of a string or array. It might be just pointing to a single character.


I have a C++ string. I need to pass this string to a function accepting a char* parameter (for example - strchr()).

a) How do I get that pointer?

b) Is there some function equivalent to strschr() that works for C++ strings?