Overview
Examples
Screenshots
Comparisons
Applications
Download
Documentation
Tutorials
Bazaar
Status & Roadmap
FAQ
Authors & License
Forums
Funding Ultimate++
Search on this site
Search in forums












SourceForge.net Logo
Home » U++ Library support » U++ Core » Why Cout() and Cerr() work so different?
icon5.gif  Why Cout() and Cerr() work so different? [message #44969] Tue, 04 August 2015 23:43 Go to next message
kov_serg is currently offline  kov_serg
Messages: 37
Registered: August 2008
Location: Russia
Member
Why this code outputs different lines of text? (OS:WinXP SP3 32bit Upp:8760)
#include <Core/Core.h>

using namespace Upp;

CONSOLE_APP_MAIN 
{
	Cout()<<"ABCD - АБВГД\n";
	Cerr()<<"ABCD - АБВГД\n";
}

Output:
ABCD - АБВГД
ABCD - ╨Р╨С╨Т╨У╨Ф


index.php?t=getfile&id=4824&private=0
  • Attachment: pic001.PNG
    (Size: 36.38KB, Downloaded 564 times)
Re: Why Cout() and Cerr() work so different? [message #44970 is a reply to message #44969] Wed, 05 August 2015 08:08 Go to previous messageGo to next message
sergeynikitin is currently offline  sergeynikitin
Messages: 748
Registered: January 2008
Location: Moscow, Russia
Contributor

Under Linux
ABCD - АБВГД
ABCD - АБВГД


SergeyNikitin<U++>( linux, wine )
{
    under( Ubuntu || Debian || Raspbian );
}
Re: Why Cout() and Cerr() work so different? [message #44971 is a reply to message #44970] Wed, 05 August 2015 08:12 Go to previous messageGo to next message
sergeynikitin is currently offline  sergeynikitin
Messages: 748
Registered: January 2008
Location: Moscow, Russia
Contributor

Win exe under wine
ABCD - ╨Р╨С╨Т╨У╨Ф
ABCD - ╨Р╨С╨Т╨У╨Ф
<--- Finished, press any key to close the window --->


SergeyNikitin<U++>( linux, wine )
{
    under( Ubuntu || Debian || Raspbian );
}
Re: Why Cout() and Cerr() work so different? [message #44973 is a reply to message #44969] Wed, 05 August 2015 13:05 Go to previous messageGo to next message
mirek is currently offline  mirek
Messages: 13975
Registered: November 2005
Ultimate Member
kov_serg wrote on Tue, 04 August 2015 23:43
Why this code outputs different lines of text? (OS:WinXP SP3 32bit Upp:8760)
#include <Core/Core.h>

using namespace Upp;

CONSOLE_APP_MAIN 
{
	Cout()<<"ABCD - АБВГД\n";
	Cerr()<<"ABCD - АБВГД\n";
}

Output:
ABCD - АБВГД
ABCD - ╨Р╨С╨Т╨У╨Ф


index.php?t=getfile&id=4824&private=0


It is because different code is used for Cerr output. Cout performs character set conversion (UTF8->console OEM charset), Cerr does not.

The reason is that conversion has some bad properties and it was deemed unlikely that somebody outputs unicode to error output. We might have been wrong... Smile

Mirek
Re: Why Cout() and Cerr() work so different? [message #44974 is a reply to message #44973] Wed, 05 August 2015 13:40 Go to previous messageGo to next message
kov_serg is currently offline  kov_serg
Messages: 37
Registered: August 2008
Location: Russia
Member
Cerr() outputs error message with directory name. It works fine until directory has russian name.
I just not understand why behaviour is different. Should it be same? May be it should be fixed.

ps: Under ubuntu it works fine becase terminal has utf-8 encoding.

#include <Core/Core.h>

using namespace Upp;

CONSOLE_APP_MAIN
{
	CoutUTF8(); // this forces behaviour to be same
	String fn="C:\\АБВ\\list.txt";
	Cout()<<"loading "<<fn<<"\n";
	Cerr()<<"problem "<<fn<<"\n";
}

[Updated on: Wed, 05 August 2015 13:52]

Report message to a moderator

Re: Why Cout() and Cerr() work so different? [message #44975 is a reply to message #44974] Wed, 05 August 2015 14:05 Go to previous messageGo to next message
kov_serg is currently offline  kov_serg
Messages: 37
Registered: August 2008
Location: Russia
Member
But this does not help. It becames even worse.

index.php?t=getfile&id=4825&private=0
  • Attachment: pic002.PNG
    (Size: 45.88KB, Downloaded 498 times)
Re: Why Cout() and Cerr() work so different? [message #44996 is a reply to message #44969] Wed, 12 August 2015 12:18 Go to previous messageGo to next message
Mindtraveller is currently offline  Mindtraveller
Messages: 917
Registered: August 2007
Location: Russia, Moscow rgn.
Experienced Contributor

I guess charset conversion fot Cout/Cerr could be a bad kind of surprise. This is something you don't wait for when use it.
Re: Why Cout() and Cerr() work so different? [message #45023 is a reply to message #44996] Thu, 20 August 2015 08:20 Go to previous message
mirek is currently offline  mirek
Messages: 13975
Registered: November 2005
Ultimate Member
To tell the truth, all is also complicated by the fact that in win32, we present itself to system as "non-UNICODE" application (because of now obsolete demand to support Win95/Win98). That means the console runs in OEM charset... So the conversion is UTF8->OEM charset Sad

Previous Topic: [GCC][C++11] error: call of overloaded 'pick(Upp::Any&)' is ambiguous
Next Topic: Dehaviour of DirectoryExists
Goto Forum:
  


Current Time: Fri Mar 29 16:04:50 CET 2024

Total time taken to generate the page: 0.01037 seconds