Saturday, May 9, 2009

C++ strings?

i'm trying to convert a string (baseStr) to an array (baseArry):





string Convert(string baseStr)


{


int baseLength = (size_t)baseStr.length();


char* baseArry = NULL;


baseArry = new char[baseLength];


strcpy_s(baseArry, baseLength, baseStr.c_str);


}





It compiles okay, but when I run it, it says that the buffer is too small. Did I allocate my memory incorrectly?

C++ strings?
change baseLength line to this


size_t baseLength = (size_t) (baseStr.length() + 1);





And Convert function should be


char *Convert(string baseStr)


and return baseArry as the result;


No comments:

Post a Comment