|
-
July 17th, 2008, 02:30 AM
#1
Building std::string obj from char*
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,
Dont forget to rate my post if you find it useful.
-
July 17th, 2008, 02:33 AM
#2
Re: Building std::string obj from char*
Please Ignore it..Got the answer..
Dont forget to rate my post if you find it useful.
-
July 17th, 2008, 03:59 AM
#3
Re: Building std::string obj from char*
For those who find this thread ...
You can do either:
Code:
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);
-
July 17th, 2008, 09:28 AM
#4
Re: Building std::string obj from char*
If you happen to invoke the char* argument taking constructor of std::string, then yes, it is necessary to have it null-terminated.
Can you help me with my homework assignment?, Before you post!, Use code tags, How to post!, Codeguru technical FAQs, C++ FAQ Lite, Stroustrup: C++ Style and Technique FAQ, Guru of the Week, Comeau C and C++ FAQs, Comeau C++ Templates FAQs, CUJ @ DDJ, Spam threshold
My Blogs : Learning C++ is fun | Abnegator's reflections
Open Threads : C++ Aha! Moments | Nature of work in C++?
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|