• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: Converting NSString to C++ std::string
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Converting NSString to C++ std::string


  • Subject: Re: Converting NSString to C++ std::string
  • From: Clark Cox <email@hidden>
  • Date: Fri, 8 May 2009 15:11:44 -0700

On Fri, May 8, 2009 at 9:56 AM, Drew Lawson <email@hidden> wrote:
> According to Alex Curylo:
>
>>
>> On 8-May-09, at 8:55 AM, email@hidden wrote:
>>
>> > mycppstring = std::string([[myNSTextField stringValue] UTF8String]);
>> >
>> >
>> > But it keeps crashing. What's the recommended way?
>>
>> I have no idea, but it works for me to simply assign it without the
>> constructor. Why, here's an example in the file I'm working on right
>> now, fancy that:
>
> The only other gotcha I can think of (because it annoys me) is that
> std::string does not play nice with null pointers.  Is it possible
> that stringValue returns nil?
>
> Hmm, I had one other thought.  There are several std::string
> constructors, depending on the parameter type.  In ObjC++, is it
> unambiguous at compile time that the expression is "const char*"?

Yes. Otherwise, it would be a compile-time error. std::string only has
two single-parameter constructors, one takes a (const char*) and one
takes a (const std::string&), so unless you've defined your own
UTF8String method that returns a std::string, none of the other
constructors will match.

--
Clark S. Cox III
email@hidden
_______________________________________________

Cocoa-dev mailing list (email@hidden)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:

This email sent to email@hidden

References: 
 >Re: Converting NSString to C++ std::string (From: Alex Curylo <email@hidden>)
 >Re: Converting NSString to C++ std::string (From: Drew Lawson <email@hidden>)

  • Prev by Date: Re: HFS Format API?
  • Next by Date: Re: NSString to bit pattern
  • Previous by thread: Re: Converting NSString to C++ std::string
  • Next by thread: Re: Converting NSString to C++ std::string
  • Index(es):
    • Date
    • Thread