Lars Gullik Bjønnes wrote: > | 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); > > ??
No. And, of course, std::strlen doesn't like unsigned chars either (actually UInt8, but let's not quibble.) > otoh... why is applicaton_support unsigned char in the first place? > what happens if you make it just char[]? Then FSRefMakePath complains. OSStatus FSRefMakePath ( const FSRef * ref, UInt8 * path, UInt32 maxPathSize ); > | I think that it's safe to cast, but am I correct? > | std::string(reinterpret_cast<char const *>(application_support)); > > We should try to avoid it. Googling (strlen FSRefMakePath), I see lots of this sort of code: char array[PATH_MAX + 1]; FSRefMakePath(&fsref, reinterpret_cast<UInt8*>(array), PATH_MAX); -- Angus