On Thu, Jan 13, 2005 at 10:06:09AM +0100, Lars Gullik Bjønnes wrote: > John Weiss <[EMAIL PROTECTED]> writes: > > | 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). > > What do you think the above snippet use?
Oh, you mean the one you ... no, wait, that just has, "+length" in it. Though I suppose you could mean "use PATH_MAX for length" there... Is there a templatized c'tor for std::string? I don't recall, and Strousdrup (the book, not the guy) is a tad difficult to lug around with the laptop to and from work each day. > | Afterward, just do a std::string::find_first_of() to search for the > | 1st '\0', then std::string::erase() from that point onward. > > PATH_MAX does not seem like a good idea. (and then you must at least > zero out application_support first.) Umm, Lars, the constructor for POD arrays *always* zeros out the elements, remember? (<bitter>It's in the Standard; I know. I spent the summer studying the bloody thing in prep for interviews. Fat load-o-good that did me...</bitter>) > Please try it out and test it for yourself. I'm just tossing off the idea. It's the first thing I'd try if faced with a strange API that wanted an unsigned char * to use as a buffer. -- John Weiss