zoukankan      html  css  js  c++  java
  • 用ofstream/ifstream 读写Unicod的TXT

    使用的平台:vs2013 控制台

    from: http://bbs.csdn.net/topics/360229403

    xiayuanzhong:

    ofstream ofs( "test.txt", ios::binary | ios::out );
    ifstream ifs( "Test_Read.txt", ios::binary | ios::in  );
    wchar_t temp[ 2 ];
    ifs.read( (char *)temp, 2 );
    memset( temp, L'', sizeof(temp) );
    ofs.write( "xFFxFE", 2 );
    int k = 0;
    while ( 1 ) {
        k ++;
        ifs.read( (char *)temp, 2 );
        if ( ifs.eof( ) ) break;//经验表明,放在这里最恰当!~
        ofs.write( (char *)temp, 2 );
    }
    ifs.close( );
    ofs.close( );
    

      

    unicode的TXT使用经验:

    1.输出 换行符

      ofstream ofs_c(FILE_NAME_C, ios::binary | ios::out);

      ofs_c.write("x0Dx00x0Ax00", 4);// " "

    2.输出空格

      WCHAR_NULL8(ofs) (ofs).write("x20x00x20x00x20x00x20x00", 8);//" " x 4

    如果问题解决起来不妥或者有更好的解决办法,麻烦请告知,帮助曾经和你一样的入门者,谢谢。
  • 相关阅读:
    Java annotation
    子类 父类强转 HttpServlet service实现
    父类 子类 强转
    HttpServlet Service方法
    java go
    IO写 PrintWriter
    IO读 BufferedReader+FileReader
    Java NIO-3
    心跳包(HeartBeat)
    Git学习笔记(一)
  • 原文地址:https://www.cnblogs.com/ourran/p/5882739.html
Copyright © 2011-2022 走看看