Article View: comp.std.c++
Article #1820Re: basic_string conversions
From: Nathan Myers
Date: Wed, 23 Aug 1995 02:21
Date: Wed, 23 Aug 1995 02:21
32 lines
1684 bytes
1684 bytes
Distribution:
In article <ncmDDnGr2.K0E@netcom.com>, Nathan Myers <ncm@netcom.com> wrote:
>> In article <MATT.95Aug17235138@physics2.berkeley.edu>,
>> Steve F. Cipolli <dscope!sfc@uu.psi.com> wrote:
>>> What is the recommended method of converting basic_string's of one
>>> parameterized type to another, and from another parameterized type itself?
In my previous posting, somebody chopped out all the indentation.
Here is the code as it should have appeared.
>std::wstring
>widen(const std::string& s, const std::locale& loc = std::locale())
>{
> using namespace std;
> vector<wchar_t> to(s.length());
> const char* from_end;
> const wchar_t* to_end;
mbstate_t st;
> if (use_facet< codecvt<char,wchar_t,mbstate_t> >(loc).convert(
> s.data(), s.data()+s.length(), from_end,
> to.begin(), to.end(), to_end, st)) != codecvt_base::ok)
> throw runtime_error();
> return wstring(to, to_end);
>}
I hope this is the last try.
---
[ comp.std.c++ is moderated. Submission address: std-c++@ncar.ucar.edu.
Contact address: std-c++-request@ncar.ucar.edu. The moderation policy
is summarized in http://dogbert.lbl.gov/~matt/std-c++/policy.html. ]
Technical Details
Message-ID:
<MATT.95Aug22182147@Austern>Path:
arc1-ca.pugleaf.net!news.duke.edu!agate!agate!MattReferences:
<MATT.95Aug17235138@physics2.berkeley.edu> <ncmDDJ83M.Dvu@netcom.com> <ncmDDnGr2.K0E@netcom.com>Show Full Headers
Complete Article Headers
Path: arc1-ca.pugleaf.net!news.duke.edu!agate!agate!Matt From: ncm@netcom.com (Nathan Myers) Newsgroups: comp.std.c++ Subject: Re: basic_string conversions Date: 23 Aug 1995 02:21:47 GMT Organization: NETCOM On-line Communication Services (408 261-4700 guest) Approved: Matt@Austern Message-ID: <MATT.95Aug22182147@Austern> References: <MATT.95Aug17235138@physics2.berkeley.edu> <ncmDDJ83M.Dvu@netcom.com> <ncmDDnGr2.K0E@netcom.com> NNTP-Posting-Host: austern.hip.berkeley.edu