473,387 Members | 2,436 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,387 software developers and data experts.

Chinese/Japanese Characters from ofstream

MrPickle
100 100+
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 4374
weaknessforcats
9,208 Expert Mod 8TB
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
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,...
1
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...
2
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 =...
0
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...
4
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:...
3
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...
12
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...
1
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...
8
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
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: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
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
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
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
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.