I need to give the function a null-terminated sequence of characters, but I cannot figure out how to go from the string literal to the char pointer eventually. The problem here is demonstrated:
#include <iostream>
#include <string>
using namespace std;
int main ()
{
std::string str ("this\0is a\0null separated\0string");
std::cout << "The size of str is " << str.size() << " bytes.\n\n";
return 0;
}
my current code is working.
std::string tmp = g_apidefs[i].ret_val +'.'+ g_apidefs[i].parm_types +'.'+ g_apidefs[i].parm_names +'.'+ g_apidefs[i].html_help;
size_t length = 1+strlen(tmp.c_str());
g_apidefs[i].dyn_def = new char[length];
memcpy(g_apidefs[i].dyn_def, tmp.c_str(), length);
char* p = g_apidefs[i].dyn_def;
while (*p) { if (*p=='.') *p='\0'; ++p; }
ok &= rec->Register(g_apidefs[i].regkey_def, g_apidefs[i].dyn_def) != 0;
... he turns .in \0, but is there a way to just have it \0first? I originally used strdup (a few lines of code), but had some platform-specific incompatibility issues.
I am wondering if there is a C ++ 11 or C ++ 14 way with this?
source
share