Re: outputting non-ASCII string problem



On Thu, 2007-15-03 at 05:12 -0500, Robert Caryl wrote:
> In place of 
> 
> std::cout << line << std::endl;
> 
> try
> 
> std::cout << line.c_str() << std::endl;

Thanks Bob. That works but I wonder why it's needed. What can std::cout
print without choking? Or is std::cout choking to begin with? Is there
another way to solve this?

Thanks in advance,
-Gezim

> 
> Bob Caryl
> 
> Gezim Hoxha wrote: 
> > Hi all,
> > 
> > I have a function that reads a file that contains some ISO-8859-1
> > encoded characters:
> > 
> > bool Locations::loadData(const Glib::ustring& file)
> > {
> > 	Glib::RefPtr<Glib::IOChannel> skeda = Glib::IOChannel::create_from_file
> > (file, "r");
> > 	
> > 	std::cout << "Encoding is " << skeda->get_encoding() << std::endl;
> > 	skeda->set_encoding("ISO-8859-1");
> > 	std::cout << "New encoding is " << skeda->get_encoding() << std::endl;
> > 	
> > 	Glib::ustring line;
> > 	int i=0;
> > 	
> > 	try
> > 	{
> > 		while ((skeda->read_line(line)) == Glib::IO_STATUS_NORMAL)
> > 		{
> > 			std::cout << "Initration: " << i << std::endl << std::flush;
> > 			ctrs.push_back(line); // ctrs is a Glib::ustring vector
> > 			std::cout << line << std::endl;
> > 			++i;
> > 		}
> > 	}
> > 	catch (Glib::Exception& e)
> > 	{
> > 		std::cout << "Something happended I supposed: " << typeid(e).name() <<
> > " and " << e.what() << std::endl;
> > 	}
> > 	return true;
> > }
> > 
> > 
> > And I've isolated the problem to be with outputting the string "line"
> > namely in:
> > std::cout << line << std::endl;
> > When a line such as the following is attempted to be printed with the
> > above statement:
> > ad,anyos,Any�5,42.5333333,1.5333333
> > 
> > This exception is thrown:
> > N4Glib12ConvertErrorE with this what:
> > Invalid byte sequence in conversion input
> > 
> > So, how am I supposed to print those types of lines?
> > 
> > Thanks,
> > -Gezim
> > 
> > _______________________________________________
> > gtkmm-list mailing list
> > gtkmm-list gnome org
> > http://mail.gnome.org/mailman/listinfo/gtkmm-list
> >   
> 
> -- 
> Robert L. Caryl Jr.
> Fiscal Systems, Inc.
> 102 Commerce Circle
> Madison, AL 35758-2706 USA
> 256-772-8922 ext. 108
> 
> This e-mail message may contain privileged or confidential information. If you are not the intended recipient, 
> you may not disclose, use, disseminate, distribute, copy or relay this message or attachment in any way. 
> If you received this e-mail message in error, please return by forwarding the message and it's attachment 
> to the sender and then delete the message and it's attachment from your computer.
> 
> Neither Fiscal Systems, Inc., nor its affiliates, accept any liability for any errors, omissions, corruption 
> or viruses in the contents of this message or any attachments that arise as a result of e-mail transmission.
> 
> 




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