Click to See Complete Forum and Search --> : Building std::string obj from char*


code_carnage
July 17th, 2008, 02:30 AM
Hello Guys,

Is it nessessary that to build string object one has to provide NULL terminated char array or just char array without NULL termination will also do..

Thanks in Advance

Regards
Prashant,

code_carnage
July 17th, 2008, 02:33 AM
Please Ignore it..Got the answer..

Zaccheus
July 17th, 2008, 03:59 AM
For those who find this thread ...


You can do either:


const char x[4] = {'a', 'b', 'c', 0};
const char y[3] = {'a', 'b', 'c'};

std::string a(&x[0]);
std::string b(&y[0], 3);

exterminator
July 17th, 2008, 09:28 AM
If you happen to invoke the char* argument taking constructor of std::string, then yes, it is necessary to have it null-terminated.