Click here to Skip to main content
15,910,358 members
Home / Discussions / C / C++ / MFC
   

C / C++ / MFC

 
AnswerRe: How to draw the 3D image using the StL file Pin
Cedric Moonen21-Apr-09 20:20
Cedric Moonen21-Apr-09 20:20 
Questionuse gdi+ to draw special picture Pin
x169m21-Apr-09 16:29
x169m21-Apr-09 16:29 
AnswerRe: use gdi+ to draw special picture Pin
Hamid_RT21-Apr-09 20:12
Hamid_RT21-Apr-09 20:12 
Questionabout SetJob().about Printer Pin
tony_bin21-Apr-09 15:41
tony_bin21-Apr-09 15:41 
QuestionPre-Allocate File Storage Pin
Hoppenfeld21-Apr-09 9:18
Hoppenfeld21-Apr-09 9:18 
AnswerRe: Pre-Allocate File Storage Pin
Stuart Dootson21-Apr-09 10:28
professionalStuart Dootson21-Apr-09 10:28 
QuestionSystray icon settings under Windows 7 Pin
Maxwell Chen21-Apr-09 8:16
Maxwell Chen21-Apr-09 8:16 
AnswerRe: Systray icon settings under Windows 7 Pin
Stuart Dootson21-Apr-09 8:39
professionalStuart Dootson21-Apr-09 8:39 
GeneralRe: Systray icon settings under Windows 7 Pin
Maxwell Chen21-Apr-09 15:30
Maxwell Chen21-Apr-09 15:30 
GeneralRe: Systray icon settings under Windows 7 Pin
miriam.l22-Sep-09 19:41
miriam.l22-Sep-09 19:41 
QuestionDetect Internet Explorer 7 Pin
bob1697221-Apr-09 7:33
bob1697221-Apr-09 7:33 
QuestionRe: Detect Internet Explorer 7 Pin
David Crow21-Apr-09 7:58
David Crow21-Apr-09 7:58 
AnswerRe: Detect Internet Explorer 7 Pin
bob1697221-Apr-09 8:18
bob1697221-Apr-09 8:18 
QuestionWho can find my import file ! mingw32 problem!!! Pin
zarelaky21-Apr-09 5:13
zarelaky21-Apr-09 5:13 
AnswerRe: Who can find my import file ! mingw32 problem!!! Pin
Stuart Dootson21-Apr-09 8:34
professionalStuart Dootson21-Apr-09 8:34 
GeneralRe: Who can find my import file ! mingw32 problem!!! Pin
zarelaky22-Apr-09 1:41
zarelaky22-Apr-09 1:41 
GeneralRe: Who can find my import file ! mingw32 problem!!! Pin
Stuart Dootson22-Apr-09 2:04
professionalStuart Dootson22-Apr-09 2:04 
GeneralRe: Who can find my import file ! mingw32 problem!!! Pin
zarelaky22-Apr-09 4:06
zarelaky22-Apr-09 4:06 
QuestionWriting a Unicode File using wofstream [modified] Pin
A&Ms21-Apr-09 4:33
A&Ms21-Apr-09 4:33 
AnswerRe: Writing a Unicode File using wofstream Pin
Stuart Dootson21-Apr-09 8:33
professionalStuart Dootson21-Apr-09 8:33 
Wide file streams in C++ actually (by default) write single byte characters to files (see this Google groups posting[^] for details). The characters you've provided aren't convertible into your default codepage, so it's game over!

I believe that if you imbue[^] your file stream with a locale[^] that has a codecvt facet[^] that converts to some Unicode encoding, then you'll get proper wide character files.

In fact, this code (which uses the appropriate codecvt facet from this CP article[^]) will do just that!:

#include <iostream>
#include <fstream>
#include <string>
using namespace std;

#include <locale>

using std::codecvt ; 
typedef codecvt < wchar_t , char , mbstate_t > NullCodecvtBase ;

class NullCodecvt
   : public NullCodecvtBase
{

public:
   typedef wchar_t _E ;
   typedef char _To ;
   typedef mbstate_t _St ;

   explicit NullCodecvt( size_t _R=0 ) : NullCodecvtBase(_R) { }

protected:
   virtual result do_in( _St& _State ,
      const _To* _F1 , const _To* _L1 , const _To*& _Mid1 ,
      _E* F2 , _E* _L2 , _E*& _Mid2
      ) const
   {
      return noconv ;
   }
   virtual result do_out( _St& _State ,
      const _E* _F1 , const _E* _L1 , const _E*& _Mid1 ,
      _To* F2, _E* _L2 , _To*& _Mid2
      ) const
   {
      return noconv ;
   }
   virtual result do_unshift( _St& _State , 
      _To* _F2 , _To* _L2 , _To*& _Mid2 ) const
   {
      return noconv ;
   }
   virtual int do_length( _St& _State , const _To* _F1 , 
      const _To* _L1 , size_t _N2 ) const _THROW0()
   {
      return (_N2 < (size_t)(_L1 - _F1)) ? _N2 : _L1 - _F1 ;
   }
   virtual bool do_always_noconv() const _THROW0()
   {
      return true ;
   }
   virtual int do_max_length() const _THROW0()
   {
      return 2 ;
   }
   virtual int do_encoding() const _THROW0()
   {
      return 2 ;
   }
} ;

int _tmain(int argc, _TCHAR* argv[])
{
   wofstream of("./a.txt",std::ios::out | std::ios::binary);
   std::locale l( std::locale(), new NullCodecvt);
   of.imbue( l ) ;
   of << "Hello";
   of.close();
   return 0;
}


Java, Basic, who cares - it's all a bunch of tree-hugging hippy cr*p

AnswerRe: Writing a Unicode File using wofstream Pin
A&Ms21-Apr-09 10:43
A&Ms21-Apr-09 10:43 
GeneralRe: Writing a Unicode File using wofstream Pin
Stuart Dootson21-Apr-09 10:51
professionalStuart Dootson21-Apr-09 10:51 
GeneralRe: Writing a Unicode File using wofstream Pin
A&Ms21-Apr-09 22:17
A&Ms21-Apr-09 22:17 
GeneralRe: Writing a Unicode File using wofstream Pin
Stuart Dootson21-Apr-09 22:28
professionalStuart Dootson21-Apr-09 22:28 
GeneralRe: Writing a Unicode File using wofstream Pin
A&Ms22-Apr-09 6:53
A&Ms22-Apr-09 6:53 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.