how can i take input in const char * in c++ ?

how can i take input in const char * instead of a string ?
by declaring that to be your input type, I suppose.

1
2
3
4
5
6
void UseConstCharArray(const char *);

void UseConstCharArray(const char * inputPtr)
{
    ... // do stuff
}


so lets say you have a std::string and you want to call that function! You need to use "c_str" function.

1
2
3
4
5
6

int main()
{
    std::string myString = "Feel the power!";
    UseConstCharArray(myString.c_str());
}


The function c_str function returns a (const char*): http://www.cplusplus.com/reference/string/string/c_str/
Topic archived. No new replies allowed.