今天在Qt上先試了一下如何建立一個Unicode的文件程式。
#include <QtCore/QCoreApplication>
#include <QFile>
#include <QTextStream>
#include <iostream>
#include <QtCore>
int main(int argc, char *argv[])
{
QCoreApplication a(argc, argv);
QFile file("binary.txt");
file.open(QIODevice::WriteOnly);
QDataStream out(&file);
//
// Create Unicode header (FFFE)
//
out << (qint8) 0xFF << (qint8) 0xFE;
file.close();
//QFile file("test.txt");
if (file.open (QIODevice::Append | QIODevice::Text)) {
QTextStream out1(&file);
out1.setCodec ("UTF-16");
out1 << "Hello World!!";
file.close();
}
return a.exec();
}
參考資料:
Qt4 Gossip: QTextStream
QDataStream Class Reference
QTextStream Class Reference
沒有留言:
張貼留言