C++ Strings – How to Convert Single Char to Null-Terminated const char*

c++charconstantsstring

I want to loop through a string of characters pull each one out and each one has to be of type const char* so I can pass it to a function. Here's an example.

string thestring = "abc123";

for(int i = 0; i < thestring.length(); i++){
    const char* theval = thestring[i]; // somehow convert this must be type const char*
    string result = func(theval);
    // ...
}

Best Answer

You can take the address of that element:

theval = &thestring[i];
Related Question