On Fri, Jan 07, 2005 at 05:18:23PM +0100, Lars Gullik Bjønnes wrote:
> Angus Leeming <[EMAIL PROTECTED]> writes:
> 
> | Given this, which is MacOS X code to fill 'application_support':
> >
> |     unsigned char application_support[PATH_MAX + 1];
> |     OSStatus const status_code =
> |         FSRefMakePath(&fsref, application_support, PATH_MAX);
> >
> | what's the correct way to create a std::string?
> >
> |     std::string(application_support) fails.
> 
> Do you know its length?
> 
>    std::string(application_support, application_support + length);

IIRC, there's a template member fn. std::string::assign() or
std::string::insert() [I forget which] that takes a begin and end
iterator.  You could use that.  For the end-iterator, just use
(application_support + PATH_MAX).

Afterward, just do a std::string::find_first_of() to search for the
1st '\0', then std::string::erase() from that point onward.

Granted, it's not ideal, but it accomplishes what you want, and avoids
the nasty reinterpret_cast<>()...

-- 
John Weiss

Reply via email to