我想将 L"你好" 写入文本文件然后再读出来,该怎样写?无论什么方法都可以,另外 ... iostream支持Unicode吗?如果使用c++的标准输入输出流该怎样来完成Unicode的读写操作呢?

解决方案 »

  1.   

    HANDLE hFile = CreateFile(_T("C:\\FOO.DAT"),
             GENERIC_WRITE, FILE_SHARE_READ,
             NULL, CREATE_ALWAYS, FILE_ATTRIBUTE_NORMAL, NULL);   if (hFile == INVALID_HANDLE_VALUE)
          AfxMessageBox(_T("Couldn't create the file!"));
       else
       {
          // Attach a CFile object to the handle we have.
          CFile myFile(hFile);
          TCHAR  ch=L"你好";
       
          // write string, without null-terminator
          myFile.Write(ch,sizeof(ch)/sizeof(TCHAR));      // We can call Close() explicitly, but the destructor would have
          // also closed the file for us. Note that there's no need to
          // call the CloseHandle() on the handle returned by the API because
          // MFC will close it for us.
         myFile.Read(chbuf,sizeof(ch)/sizeof(TCHAR));
          myFile.Close();
       }
    仅作参考