I am trying to copy a string which might contain null characters in the middle to a char array. I have constructed the following function.
void SaveStringToChar(string &mystring,const char * &ArrChar)
{//begin function
std::string str;
char * writable = new char[str.size() + 1];
std::copy(str.begin(), str.end(), writable);
writable[str.size()] = '\0';
ArrChar = writable;
}//end function
my question is this method guarantees that I wont lose the characters after a null element. and my other question is I get this linker error which I don't know what it means.
/tmp/ccUpCRaz.o: In function `Parser::RuleParser(char const*)': Parser.cpp:(.text+0x3f6): undefined reference to Parser::SaveStringToChar(std::basic_string, std::allocator >&, char const*&)' collect2: ld returned 1 exit status
anyhint please.
this is the function I pass things to compare.
void Search( size_t TextLength, const char *Text, const vector<const char *> &patterns );
std::string::c_str()?\0. Even if you test it with one compiler, it may not behave in the same way on another.c_str()return a null-terminated string, you indeed have no way of telling if you really reached the end of the string when displaying it. Now an important question is: why would you want to deal with null-terminated strings if you know for sure they can contain null characters ? Sticking withstd::stringseems far less risky.c_str()to return all the characters of the string, null or not, in the resulting array. Could anyone confirm/infirm ?