473,769 Members | 7,320 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

locale and wcin, wcout, wfstream

Hi,

consider the following program loc.cc

#include <iostream>
#include <fstream>
#include <string>
#include <locale>

using namespace std;

int main(){
char *l=setlocale(LC _ALL,"de_DE.UTF-8");
if (!l) {cerr<<"locale problem"<<endl; return 1;}
wstring w;
wcin>>w;
wostream &outf=wcout; // (*) works
// wofstream outf("xx"); // (**) doesn't work
outf<<w<<L" "<<w.size()<<en dl;
return 0;
}
If the program is called with
loc <infile
where infile contains the the UTF-8 encoded line

"The_german_wor d_for_apples_is _Äpfel"

I get the output

"The_german_wor d_for_apples_is _Äpfel 35"

However, if the line (*) is commented out and instead the line (**) is
used the file xx is empty. This can be fixed by

outf.imbue(loca le("de_DE.UTF-8"));

after the the declaration of outf and before outputting the string. On
the other hand omitting the "setlocale" call and instead imbuing wcin
with the locale directly yields

"The_german_wor d_for_apples_is _ 30"
This seems a little odd. Does that mean wcin and wcout are locale-aware
after a setlocale call whereas "ordinary" files need an imbue call? If
so why?
Nov 10 '06 #1
0 1931

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
3075
by: Alex Mizrahi | last post by:
Hello, All! i admit that it's better to ask questions connected with atl/mfc classes in special newsgroups, but seems like people there are interested more in discussing stuff like MFC GUI than C++ 8-/, so i'll better ask here too.. CStringW is a class in atl/mfc dealing with strings 8-]. the only typecast operator i found is to PCXSTR that is LPCWSTR that is simply "const unsigned short*" (wchar_t is unsigned short). wcout accepts...
7
9346
by: jalkadir | last post by:
WinXP P3 MinWing-GCC-3.4.3 When compiling the program below, I get a message that reads: wcout' is not a member of `std' What am I doing wrong? This message popping up too often!! >:( TIA
3
4748
by: Steven T. Hatton | last post by:
There's probably something obvious I'm missing here, but I can't seem to figure out how to get this to work: ostream_iterator<wstring, wchar_t>(wcout,"\n")); When I try to compile it, I get an error telling me it doesn't like the char. wcout.widen('\n') doesn't work here because it wants a string. Is there a way to make this work? -- NOUN:1. Money or property bequeathed to another by will. 2. Something handed
7
9779
by: Ralf Goertz | last post by:
Hi, since my previous post <455440ad$0$30326$9b4e6d93@newsspool1.arcor-online.netis still unanswered I'd like to rephrase my question. In order to read/write a wstring in UTF-8 encoding it is *not* sufficient to imbue the stream with a locale like "de_DE.UTF-8". Doing so only takes care of facets of decimal numbers and the like. Rather, one has to call locale::global("de_DE.UTF-8"). Is this behaviour conforming to the standard? And if...
1
3606
by: iwongu | last post by:
Hi, I have a question about std::wcout and its underlying C functions. According to C99, a stream have an orientation type that is one of byte-oriented or wide-one, and it is determined by the first using C function on that stream. And the specific orientation functions should not be applied to the stream that have other orientation.
2
8395
by: interec | last post by:
I have a simple program in which I want to read a wstring using wcin and then output the same string using wcout. The program takes a few words separated by spaces as input. The problem is that only the first word is outputted. Everything after the first space seems to be lost in the output. My OS is redhat hat linux 4 ES. gcc 3.4.6. How do I fix this and why its not working? Thanks Code
2
7773
by: Ralf Goertz | last post by:
Hi, can I mix output to cout and wcout? It seems that if I write to cout first it works fine but if I start with wcout the output to cout vanishes. I assume that is has to do with the initialization of standard output, right? #include <iostream> using namespace std;
2
3896
by: year1943 | last post by:
There was the same topic not so long ago, but as I see it stays w/o answer: http://groups.google.ru/group/comp.lang.c++/browse_thread/thread/9a05d7bba9394a60/fe109c899f916871?lnk=gst&q=locale+imbue&rnum=1&hl=ru#fe109c899f916871 As Bjarne Stroustrup said in his book, "in Stroustrup (retranslated from German) "Setting the global locale does not affect existing input/output streams. The streams continue to use those locales that were...
44
4384
by: Ioannis Vranos | last post by:
Has anyone actually managed to print non-English text by using wcout or wprintf and the rest of standard, wide character functions?
0
9589
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
10049
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
9997
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9865
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
1
7413
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5309
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5448
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
3965
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
3
2815
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.