[gameprogrammer] Re: Is this valid?
- From: "Olivier Delannoy" <olivier.delannoy@xxxxxxxxx>
- To: gameprogrammer@xxxxxxxxxxxxx
- Date: Fri, 25 Jan 2008 08:24:17 +0100
However you can write something like
std::string s;
s.assign(strlen("Hello world"), '\0');
strcpy(&s[0], "Hello world");
On Jan 25, 2008 7:26 AM, Matthew Weigel <unique@xxxxxxxxxxx> wrote:
> Kevin Jenkins wrote:
> > std::string s;
> > s.reserve(strlen("Hello world"));
> > strcpy(s.c_str(), "Hello world");
>
> That makes me cry in so many ways.
>
> 1. The signature for string.c_str() is "const charT* c_str() const" so
> assigning it a value is a bad thing - and not valid.
> 2. Please, never use strcpy() - even if it's with a constant string. Use
> strncpy(), and understand its semantics.
> 3. Why are you mixing C and C++ string manipulation? You are trying to use
> your std::string as a char*, why not just use a char*?
> 4. Alternatively, why not use
> std::string s("Hello world");
> to assign the string?
> --
> Matthew Weigel
> hacker
> unique & idempot.ent
>
>
> ---------------------
> To unsubscribe go to http://gameprogrammer.com/mailinglist.html
>
>
>
---------------------
To unsubscribe go to http://gameprogrammer.com/mailinglist.html
- Follow-Ups:
- [gameprogrammer] Re: Is this valid?
- From: Brian
- References:
- [gameprogrammer] Is this valid?
- From: Kevin Jenkins
- [gameprogrammer] Re: Is this valid?
- From: Matthew Weigel
Other related posts:
- [gameprogrammer] Re: Is this valid?
- From: Brian
- [gameprogrammer] Is this valid?
- From: Kevin Jenkins
- [gameprogrammer] Re: Is this valid?
- From: Matthew Weigel