stl wstring and string.

D

DFB_NZ

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.
 
V

Victor Bazarov

DFB_NZ said:
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
 
D

DFB_NZ

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..?
 
J

Jonathan Turkanis

DFB_NZ said:
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
 
J

Jerry Coffin

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...
 
L

Larry Brasfield

DFB_NZ said:
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.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,767
Messages
2,569,572
Members
45,045
Latest member
DRCM

Latest Threads

Top