473,586 Members | 2,463 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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 7684
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****@statest reet.com> wrote in message
news:11******** **************@ c13g2000cwb.goo glegroups.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************* **********@hotm ail.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
64125
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
5848
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 are A::setResponse(std::wstring &) ---> This is indeed the signature I am using this function as:
8
16470
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, is that also the case with wstring? Another related question that I have is, is it advisable to use wstring than string for unicode support? To...
14
12175
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++ books (Effective C++, More Effective C++, Exceptional C++, More Exceptional C++, C++ FAQs, Addison Wesley 2nd Edition) Authors of these books...
9
7451
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
9605
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. However the open member function of is not templated, and use const char* as filename. I have my filename as wstring, where c_str() returns const...
10
10102
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 Appendix D recommendation won't compile in Microsoft VC++ 6.0). My question is in reference to MultiByte Character Sets. Will this code perform as...
10
4848
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() << endl;
1
3805
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() << endl;
10
8238
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
7915
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...
0
7841
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language...
0
8339
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...
1
7965
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...
0
8220
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...
0
6617
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then...
0
3838
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...
0
3869
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
1452
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.