By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
446,192 Members | 858 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 446,192 IT Pros & Developers. It's quick & easy.

stl wstring and string.

P: n/a
Hi.

I have had problems compiling a simple program that uses wstring.

So....I wrote a small application that reads using char, fgetc etc in a
text file and writes it out to another text file. The japanese was
preserved in the outfile.

I am a c++ programmer from M$ and I use TCHAR etc so I am no stranger
to unicode on windows.

I am using eclipse, cgywin, windows 2k (Japanese Language support). gcc
3.3.3.

So why would I use wstring and wchar_t when string and char work with
Japanese anyway?

Thanks.

Jul 23 '05 #1
Share this Question
Share on Google+
6 Replies


P: n/a
DFB_NZ wrote:
I have had problems compiling a simple program that uses wstring.
This is covered in the FAQ 5.8.
So....I wrote a small application that reads using char, fgetc etc in a
text file and writes it out to another text file. The japanese was
preserved in the outfile.

I am a c++ programmer from M$ and I use TCHAR etc so I am no stranger
to unicode on windows.

I am using eclipse, cgywin, windows 2k (Japanese Language support). gcc
3.3.3.

So why would I use wstring and wchar_t when string and char work with
Japanese anyway?


I don't know. Why would you use something you don't seem to need?

V
Jul 23 '05 #2

P: n/a
Could you be more specific about "This is covered in the FAQ 5.8."
ie could you please paste a URL link or something.

I found that even in MSVC 6.0 if I use char and read/write a japanese
file the japanese is preserved. I am confused. I thought I had to use
TCHAR everywhere for non-ascii text. I compiled using MBCS and
therefore used char to read in japanese text then write it out to a
text file. the output file still had japanese in it.
Can someone offer anytype of explanation..?

Jul 23 '05 #3

P: n/a
DFB_NZ wrote:
Could you be more specific about "This is covered in the FAQ 5.8."
ie could you please paste a URL link or something.


Definitely. Start here: http://www.slack.net/~shiva/welcome.txt
Jul 23 '05 #4

P: n/a
DFB_NZ wrote:
Could you be more specific about "This is covered in the FAQ 5.8."
ie could you please paste a URL link or something.

I found that even in MSVC 6.0 if I use char and read/write a japanese
file the japanese is preserved.
If you open files in binary mode and use the "C" locale you can use narrow
streams for transfering data without regard to its textual content.

If you need to do more than transfer data between files, e.g., if you need to
perform regex subsitutions, you should imbue the file stream with an appropriate
local and use wide characters.
I am confused. I thought I had to use
TCHAR everywhere for non-ascii text. I compiled using MBCS and
therefore used char to read in japanese text then write it out to a
text file. the output file still had japanese in it.
Can someone offer anytype of explanation..?


Jonathan
Jul 23 '05 #5

P: n/a
DFB_NZ wrote:

[ ... ]
So....I wrote a small application that reads using char, fgetc etc in a text file and writes it out to another text file. The japanese was
preserved in the outfile.
[ ... ]
So why would I use wstring and wchar_t when string and char work with
Japanese anyway?


It all depends on what you're doing with the text. Reading and writing
narrow characters will work fine as long as your program basically just
passes the text through without caring about how many of those narrow
characters go to compose on real Japanese character.

If, however, your program needs to deal with the characters as
characters and (for example) cares about the boundary between one
character and the next, then converting them to wide characters will
start to make a lot more sense. The Unicode encodings are mostly pretty
easy (UCS-4 is trivial, but even UTF-8 is still fairly simple) but
(just for one example) Shift-JIS is seriously ugly, to put it nicely --
if you have to deal with it, you'd strongly prefer to use some
pre-written code. Of course, UCS-4 is rare and Shift-JIS almost
unavoidable...

--
Later,
Jerry.

The univserse is a figment of its own imagination.

Jul 23 '05 #6

P: n/a
"DFB_NZ" <db****@statestreet.com> wrote in message
news:11**********************@c13g2000cwb.googlegr oups.com...
Could you be more specific about "This is covered in the FAQ 5.8."
ie could you please paste a URL link or something.
This was posted earlier in this very thread:
http://www.slack.net/~shiva/welcome.txt
Go there. It leads to the FAQ. If you are too lazy to
do that, I am not inclined to help and many other will
feel the same way.
I found that even in MSVC 6.0 if I use char and read/write a japanese
file the japanese is preserved. I am confused. I thought I had to use
TCHAR everywhere for non-ascii text. I compiled using MBCS and
therefore used char to read in japanese text then write it out to a
text file. the output file still had japanese in it.
Can someone offer anytype of explanation..?


--
--Larry Brasfield
email: do***********************@hotmail.com
Above views may belong only to me.
Jul 23 '05 #7

This discussion thread is closed

Replies have been disabled for this discussion.