Re: Can't write ustring to std::cout [Was: Re: string problems]



On Fri, 2007-10-05 at 15:49 +0200, Philipp Klaus Krause wrote:
> Sebastian schrieb:
> > If you don't mind using Glibmm for reading the file:
> > 
> > Glib::ustring s;
> > Glib::RefPtr<Glib::IOChannel> ioc =
> > Glib::IOChannel::create_from_file(filename, "r");
> > ioc->read_to_end(s);
> 
> I'de prefer not to use IOChannel, since it seems more elegant to use
> generic istream and ostream (so I can use cout in place of an output
> file if I want to).
> 
> I just did another test (line is a Glib::ustring):
> 
> std::string linetmp;
> std::getline(source, linetmp);
> line = linetmp;
> linetmp = line;
> std::cout << linetmp << "\n";
> 
> works,
> 
> std::string linetmp;
> std::getline(source, linetmp);
> line = linetmp;
> linetmp = line;
> std::cout << line << "\n";
> 
> still doesn't.

I believe that this is relevant:
http://www.gtkmm.org/docs/glibmm-2.4/docs/reference/html/classGlib_1_1ustring.html#_details
(see "Glib::ustring and stream input/output")

I think you need to know what encoding your string has, and convert it
when appropriate. You should also catch exceptions for when this fails.

-- 
murrayc murrayc com
www.murrayc.com
www.openismus.com




[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]