usman999_1
April 9th, 2003, 09:47 AM
Hi *!
I get from a lib a not null-terminated string back. I am want to copy it to my local std::string. I also get back the total length of C-string. Here is what i am doing
char* pChr = NULL;
short nChrLen = 0;
std::string szMyString = "";
// Call some lib functions with pChr and &nChrLen....
if(pChr){
szMyString = pChr;
szMyString[nChrLen] = '\\0';
}
It works correctly but is it the corrrect way, coz if i don't null terminate the string i get some junk stuff (thats obvious) but the copying of string reads some part of memory that it is not supposed to. Whats the correct way to do that????????
Thanks in Advance,
Regards,
Usman.
I get from a lib a not null-terminated string back. I am want to copy it to my local std::string. I also get back the total length of C-string. Here is what i am doing
char* pChr = NULL;
short nChrLen = 0;
std::string szMyString = "";
// Call some lib functions with pChr and &nChrLen....
if(pChr){
szMyString = pChr;
szMyString[nChrLen] = '\\0';
}
It works correctly but is it the corrrect way, coz if i don't null terminate the string i get some junk stuff (thats obvious) but the copying of string reads some part of memory that it is not supposed to. Whats the correct way to do that????????
Thanks in Advance,
Regards,
Usman.