C++ convert char to const char*

后端 未结 5 1190
情歌与酒
情歌与酒 2020-12-10 03:42

Basically i just 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. heres a example. Th

5条回答
  •  情深已故
    2020-12-10 04:08

    Usually a const char * is pointing to a full null-terminated string, not a single character, so I question if this is really what you want to do.

    If it's really what you want, the answer is easy:

    theval = &thestring[i];
    

    If the function is really expecting a string but you want to pass it a string of a single character, a slightly different approach is called for:

    char theval[2] = {0};
    theval[0] = thestring[i];
    result = func(theval);
    

提交回复
热议问题