473,320 Members | 1,722 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,320 software developers and data experts.

problem about wofstream

With a wofstream, we can input wstring into a file. But when i input
some wide character of chinese characters into a file, some error
occur.
With the implementation of STLport 4.62, the wstring of chines
characters were written to the file; But with the implementation of
MS, that is both in VC6.0 and Visual Studio 2005, noting was written
to the file.I don't know why and I wonder to know what the C++
standard said about this? What does the standard guarantees while
dealing with unicode characters?Where could I find such information?
Thanks for any advice.
#include <fstream>

int main()
{
std::wofstream strm2("test.txt");
strm2 << L"ÎÒ°®±±¾©Ìì°²ÃÅ";

return 0;
}

Mar 30 '07 #1
3 3669
On Mar 30, 2:47 pm, "mimi" <cainiaodelixi...@gmail.comwrote:
With a wofstream, we can input wstring into a file. But when i input
some wide character of chinese characters into a file, some error
occur.
With the implementation of STLport 4.62, the wstring of chines
characters were written to the file; But with the implementation of
MS, that is both in VC6.0 and Visual Studio 2005, noting was written
to the file.I don't know why and I wonder to know what the C++
standard said about this? What does the standard guarantees while
dealing with unicode characters?Where could I find such information?
Thanks for any advice.
#include <fstream>

int main()
{
std::wofstream strm2("test.txt");
strm2 << L"ÎÒ°®±±¾©Ìì°²ÃÅ";

return 0;
I think u should call strm2.close() before return 0,and i find it can
good work.
Mar 30 '07 #2
On Mar 30, 1:47 pm, "mimi" <cainiaodelixi...@gmail.comwrote:
With a wofstream, we can input wstring into a file. But when i input
some wide character of chinese characters into a file, some error
occur.
With the implementation of STLport 4.62, the wstring of chines
characters were written to the file; But with the implementation of
MS, that is both in VC6.0 and Visual Studio 2005, noting was written
to the file.I don't know why and I wonder to know what the C++
standard said about this? What does the standard guarantees while
dealing with unicode characters?Where could I find such information?
Thanks for any advice.
#include <fstream>

int main()
{
std::wofstream strm2("test.txt");
strm2 << L"我爱北京天安门";

return 0;

}
The wide output streams in MSVC don't act as you would expect. The
streams are not able to handle any characters outside the 0..255
range.

To do better you'll have to get different libraries, or write your own
wrapper to do the translations for the formats you want to use.

You may also find that you have problems with the source code if you
drop those characters in like that too, but I admit to being unsure as
to what text formats the compiler assumes or can read.
K

Mar 30 '07 #3
"Kirit Sælensminde" <ki****************@gmail.comwrote in message
news:11**********************@y80g2000hsf.googlegr oups.com...

On Mar 30, 1:47 pm, "mimi" <cainiaodelixi...@gmail.comwrote:
With a wofstream, we can input wstring into a file. But when i input
some wide character of chinese characters into a file, some error
occur.
With the implementation of STLport 4.62, the wstring of chines
characters were written to the file; But with the implementation of
MS, that is both in VC6.0 and Visual Studio 2005, noting was written
to the file.I don't know why and I wonder to know what the C++
standard said about this? What does the standard guarantees while
dealing with unicode characters?Where could I find such information?
Thanks for any advice.
#include <fstream>

int main()
{
std::wofstream strm2("test.txt");
strm2 << L"???????";

return 0;

}
The wide output streams in MSVC don't act as you would expect. The
streams are not able to handle any characters outside the 0..255
range.

[pjp] You're talking about the default codecvt facet, which has this
limitation. The wide streams work fine.

To do better you'll have to get different libraries, or write your own
wrapper to do the translations for the formats you want to use.

[pjp] Or get a better codecvt facet. See, for example, our Compleat
Library add-on, which defines dozens.

P.J. Plauger
Dinkumware, Ltd.
http://www.dinkumware.com
Mar 30 '07 #4

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

Similar topics

117
by: Peter Olcott | last post by:
www.halting-problem.com
7
by: kaalus | last post by:
Hi All, I just tried to use wide streams with C++. But something really strange is happening (my compiler is MSVC, wchar_t size is 2 bytes): std::wofstream s("a"); s << L'A'; s.close(); ...
28
by: Jon Davis | last post by:
If I have a class with a virtual method, and a child class that overrides the virtual method, and then I create an instance of the child class AS A base class... BaseClass bc = new ChildClass();...
6
by: Ammar | last post by:
Dear All, I'm facing a small problem. I have a portal web site, that contains articles, for each article, the end user can send a comment about the article. The problem is: I the comment length...
16
by: Dany | last post by:
Our web service was working fine until we installed .net Framework 1.1 service pack 1. Uninstalling SP1 is not an option because our largest customer says service packs marked as "critical" by...
11
by: FNX | last post by:
I'm stumbling around a little bit here trying to get a feel for wide/Unicode functionality. I'm pretty up on C++ in general, streaming stuff not so much. If I run the following code, I get a...
2
by: Mike Collins | last post by:
I cannot get the correct drop down list value from a drop down I have on my web form. I get the initial value that was loaded in the list. It was asked by someone else what the autopostback was...
3
by: jraul | last post by:
Why does the following code create an empty file? I am using Windows XP. #include <iostream> #include <fstream> int main() { std::wofstream fout("data.txt");
6
by: Jeffrey Walton | last post by:
Hi All, I'm attempting to write a wstring to a file by way of wofstream. I'm getting compression on the stream (I presume it is UTF-8). How/where do I invoke an alternate constructotor so that...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 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 former...

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.