Go4Expert (http://www.go4expert.com/)
-   C (http://www.go4expert.com/forums/c/)
-   -   output unicode to outfile (http://www.go4expert.com/forums/output-unicode-outfile-t26153/)

air0forceb914 28Jun2011 03:24

output unicode to outfile
Dear c/g++ advanced programers or ubuntu-linux programers:
I copied and tried to test a piece simple code which is used for
(Hardcoding a Unicode String) from the book (
C++ Cookbook) by D. Ryan Stephens, Christopher Diggins, Jonathan
Turkanis, and Jeff Cogswell
at Chapter 13, Internationalization, section 1: Hardcoding a Unicode
example 13-1, it can compile and run on my g++4.5.2(ubuntu10.04 upgrade kernel to 2.6.35-25), but I don't quite
satisfy its result

//Example 13-1 Hardcoding a Unicode string
#include <iostream>
#include <fstream>
#include <string>
 using namespace std;
 int main() {
  // Create some strings with Unicode characters
 wstring ws1 = L"Infinity: \u221E";
 wstring ws2 = L"Euro: \x20ac";
  wchar_t w[] = L"Infinity: \u221E";
  wofstream out("tmp\\unicode.txt");
 out << ws2 << endl;
 wcout << ws2 << endl;

root@eric-laptop:/home/eric/cppcookbook# ./a.out
Euro: EUR
root@eric-laptop:/home/eric/cppcookbook# ls -l -a
total 56
drwxr-xr-x 2 eric eric 4096 2011-06-25 22:51 .
drwxr-xr-x 60 eric eric 4096 2011-06-25 22:51 ..
-rwxr-xr-x 1 root root 8666 2011-06-25 22:51 a.out
-rw-r--r-- 1 eric eric 7372 2011-06-25 20:07 erreta
-rw-r--r-- 1 eric eric 750 2011-05-21 09:38 example12-1.cpp
-rw-r--r-- 1 eric eric 385 2011-06-25 22:51 example13-1.cpp
-rw-r--r-- 1 eric eric 709 2011-06-25 21:12 example7-11.cpp
-rw-r--r-- 1 eric eric 366 2011-06-25 20:02 example7-12.cpp
-rw-r--r-- 1 eric eric 954 2011-06-25 19:02 example7-2.cpp
-rw-r--r-- 1 eric eric 402 2011-06-01 20:55 example9-1.cpp
-rw-r--r-- 1 root root 0 2011-06-25 22:51 tmp\unicode.txt
-rw-r--r-- 1 eric eric 564 2011-06-25 19:00 utils.h
as you can see , it didn't output to file (tmp\unicode.txt) anything(size 0 and out.good() = 0).
but it did output a little thing on screen. Why is that? is that
suppose it should be on your system?
according to book's author, this code is work under CodeWarrior(Metrowerk) aound 2006
It certainly have other way(some similar as vc++ 2005) can output unicode to file, but
I like to know why this way is not work on my system.

looking to see any advancer's help/hint/link and thanks a lot in
advance, Eric, ericlin@fsshl.zzn.com, air0forceb914@aol.com

xpi0t0s 28Jun2011 17:29

Re: output unicode to outfile
You don't close the file, so maybe the data is lost on exit. Try explicitly closing the file after you've written to it.

xpi0t0s 28Jun2011 17:31

Re: output unicode to outfile
Also putting a backslash in the middle of the name will make it tricky to access. Try just calling the file "unicode.txt", or if you meant "/tmp/unicode.txt" then don't try to do that with backslashes.

All times are GMT +5.5. The time now is 10:32.