473,386 Members | 1,832 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,386 software developers and data experts.

stl wstring and string.

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
6 7670
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
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
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
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
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
"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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

6
by: gerg | last post by:
How would one convert a wstring to a string? This is what I have so far: bool copyto(std::string& l,std::wstring& r) { bool ret = false; size_t i = 0; const size_t n = r.length()+1;
3
by: uday.sen | last post by:
Hi, I am porting a piece of code from VC++ to linux platform. My compiler is g++ 3.2.2. I am getting following error: no matching function for call to A::setResponse(std::wstring) candidates...
8
by: Divick | last post by:
Hi all, can somebody tell how much std::wstring is supported across different compilers on different platforms? AFAIK std::string is supported by almost all C++ compilers and almost all platforms,...
14
by: rohitpatel9999 | last post by:
Hi While developing any software, developer need to think about it's possible enhancement for international usage and considering UNICODE. I have read many nice articles/items in advanced C++...
9
by: Mwob | last post by:
Hi, I have a very simple function, declared like this: wstring CMyClass::GetDate() { .... wcsftime (sDateString,255,L"%d-%b-%Y",&dTmpDate); wstring sText(sDateString); return sText;
9
by: toton | last post by:
Hi, I have my program using wstring everywhere instead of string. Similarly I need to process some file, which contains unicode or ascii character. I need to stream them. Thus I use wifstream etc....
10
by: Jeffrey Walton | last post by:
Hi All, I've done a little homework (I've read responses to similar from P.J. Plauger and Dietmar Kuehl), and wanted to verify with the Group. Below is what I am performing (Stroustrup's...
10
by: v4vijayakumar | last post by:
1. why the following program is not working as expected? #include <iostream> using namespace std; int main() { string t("test"); wcout << (wchar_t *) t.c_str() << endl; wcout << t.c_str()...
1
by: v4vijayakumar | last post by:
1. Why the following program is not working as expected? #include <iostream> using namespace std; int main() { string t("test"); wcout << (wchar_t *) t.c_str() << endl; wcout << t.c_str()...
10
bajajv
by: bajajv | last post by:
Hi, I was trying to implement CString with std::string and std::wstring. class CString { public: std::string str; CString() {str = "ABCD";} //this works }: class CString {
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
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,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
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...

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.