| 
UID:136309
注册时间2012-09-13最后登录2020-04-15在线时间2784小时
发帖1247搜Ta的帖子精华2金钱13131威望1310贡献值11好评度1302
访问TA的空间加好友用道具
     | 
 
嗯,这个问题 的代码在这里:QString写入文本文件,char来读取发生错误  [Qt]测试QString写入char读取是否存在中文问题.7z (1 K) 下载次数:0 我把代码贴出来吧: #include <QString>#include <QFile>#include <iostream>using namespace std;int main( void ){    cout << "要测试QString写入,QString读取是否出现中文乱码的现象。\n";    QFile file( QObject::tr( "test.txt" ) );    if ( !file.open( QIODevice::WriteOnly ) )    {        cout << "以写入方式打开错误!\n";        return 1;    }    QString testStr( QObject::tr( "你好,我喜欢你!" ) );    file.write( testStr.toAscii( ) );    cout << "文件写入完毕!\n";    file.close( );    cout << "开始文件的读取";    QFile file2( QObject::tr( "test.txt" ) );    if ( !file2.open( QIODevice::ReadOnly ) )    {        cout << "以读取方式打开错误!\n";        return 1;    }    char retStr[5] = { 0 };    file2.read( retStr, 4 );    file2.close( );    cout << "现在输出字符串:" << retStr << '\n';    return 0;}
在Ubuntu 下测试,发现出现这样的结果:  本来读取4字节,QFile 莫名地少读了1个字节,这是怎么回事呢?
 |