473,587 Members | 2,505 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Chinese/Japanese Characters from ofstream

MrPickle
100 New Member
I am tokenizing a string and sending it to a ofstream but I am getting strange results.

The \n sequence isn't working; it doesn't go to a new line.
I'm getting Chinese/Japanese characters in the file.

I think this may be due to compiling the project with the unicode character set rather than multibyte character set, but that's a guess.

Here's my code:
Expand|Select|Wrap|Line Numbers
  1. void Tokenize(std::string str, std::vector<std::string>& vs)
  2. {
  3.     std::string s;
  4.     std::stringstream ss(str);
  5.     vs.clear();
  6.     while(ss >> s) vs.push_back(s);
  7. }
  8.  
  9.  
  10. //...
  11.  
  12. std::ofstream osp("prt.txt");
  13. std::string line = "begin particle \"name\"";
  14. std::vector<std::string> tokens;
  15. Tokenize(line, tokens);
  16. if(!tokens.empty())
  17. {
  18.     if(tokens[0] == "begin")
  19.     {
  20.         if(tokens[1] == "particle")
  21.         {
  22.             char open = tokens[2][0];
  23.             char close = tokens[tokens.size()-1][tokens[tokens.size()-1].length()];
  24.             osp << open << " " << tokens[2] << " " << close << tokens[tokens.size()-1] << "\n";
  25.         }
  26.     }
  27. }
Output:
斖斖斖쀀
May 6 '09 #1
1 4418
weaknessforcats
9,208 Recognized Expert Moderator Expert
Firstly, you cannot use a Unicode string with a C++ string object. You have to use a wstring object.

Second, the basic_string<>: :operator>> skips whitespace. Since the \n is whitesace, it gets skipped.

What is it you are trying to do?
May 6 '09 #2

Sign in to post your reply or Sign up for a free account.

Similar topics

2
5168
by: Jim E. | last post by:
Using VC++ on an application for English Win 95/98 thru XP, how can I display multi-byte characters (Asian languages or roman characters with accent marks) in standard MFC controls like CEdit, RichEdit, ListCtrl's, etc? I know how to print Japanese/Chinese characters in CDCs using the correct code page and MultiByteToWideChar, but I cannot...
1
11988
by: GPenn | last post by:
SQL 2000, latest SP. We currently have the need to store data from a UTF-8 application in multiple languages in a single database. Our findings thus far support the fact that single-byte and double-byte characters can be held in the same DB without issue. However, when holding two sets of DIFFERING double-byte characters (i.e. Chinese and...
2
3691
by: Joseph | last post by:
Hello. I have this problem. See I have a transformed XML file and I checked its contents prior to outputting it to excel file via responseset. here is the gist of the code: XmlReader reader = myEsiCommand.ExecuteXmlReader(); reader.MoveToContent(); string myCSV = reader.ReadInnerXml(); //Load the xml fragment into the document...
0
1246
by: Shrek | last post by:
HELP: I write a C# class which uses J# class java.io.FileOutputStream,java.util.ZipInputStream and so on to do oprations on zip file. For example: When I add a file '1.txt' into 'hah.zip',everything goes well. But if I add a file named '你好.txt',whose name contains Chinese or Japanese characters,the zip file corrupts.
4
2244
by: wheel | last post by:
I have already built in support for multiple languages in some of my applications, but so far they have only used Western languages (English, Spanish, etc). I need to add some Far East languages: Korean, Japanese, and Chinese. Can anyone with experience in this area tell me of any special considerations? Access 2003. I've read here that the...
3
2124
by: PHP Wooer | last post by:
Can anyone provide me the simplest working solution to send mails in a multilingual website that too with no issues relating to display of characters, as of now I have find a solution which is working quite well, which is to paste a japanese or chinese lang. sentences to an editor like dreamweaver in design mode and paste the generated char...
12
2732
by: Steve Howell | last post by:
The never-ending debate about PEP 3131 got me thinking about natural languages with respect to Python, and I have a bunch of mostly simple observations (some factual, some anecdotal). I present these mostly as food for thought, but I do make my own continent-by-continent recommendations at the bottom of the email. (My own linguistic...
1
2256
by: greggorob64 | last post by:
Hello, I am working with a system developed several years ago, and was recently internationalized to support unicode languages. I am running into a very frustrating and challenging problem: In 99% of the textboxes, entering chinese (or japanese or arabic) characters (using windows IME), in any amount and length, will show up and puts...
8
6130
by: vaskarbasak | last post by:
Hi, I'm having problems displaying Chinese and Japanese characters on Swing components. I know some conversion should be done. Do you have some source code sample or any idea ? Thanks! vaskar
0
7920
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
7849
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
8215
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. ...
1
7973
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
6626
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...
1
5718
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 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 a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes...
1
1454
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
1189
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating...

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.