• <ins id="pjuwb"></ins>
    <blockquote id="pjuwb"><pre id="pjuwb"></pre></blockquote>
    <noscript id="pjuwb"></noscript>
          <sup id="pjuwb"><pre id="pjuwb"></pre></sup>
            <dd id="pjuwb"></dd>
            <abbr id="pjuwb"></abbr>

            逛奔的蝸牛

            我不聰明,但我會很努力

               ::  :: 新隨筆 ::  ::  :: 管理 ::
            #include <iostream>
            #include 
            <QFile>
            #include 
            <QImage>
            #include 
            <QMap>
            #include 
            <QColor>

            class C {
            public:
                C(quint32 value 
            = 0) :
                    value(value) {
                }

                
            // Override operator << and >>.
                friend QDataStream &operator<<(QDataStream &out, const C &obj);
                friend QDataStream 
            &operator>>(QDataStream &in, C &obj);

                quint32 getValue() 
            const {
                    
            return value;
                }

            private:
                quint32 value;
            };

            QDataStream 
            &operator<<(QDataStream &out, const C &obj) {
                out 
            << obj.value;

                
            return out;
            }

            QDataStream 
            &operator>>(QDataStream &in, C &obj) {
                in 
            >> obj.value;

                
            return in;
            }

            /**
             * Copy a file
             
            */
            bool copy(
            const QString &source, const QString &dest) {
                QFile sourceFile(source);
                
            if (!sourceFile.open(QIODevice::ReadOnly)) {
            #ifdef DEBUG
                    std::cerr 
            << sourceFile.errorString().toStdString() << std::endl;
            #endif
                    
            return false;
                }

                QFile destFile(dest);
                
            if (!destFile.open(QIODevice::WriteOnly)) {
            #ifdef DEBUG
                    std::cerr 
            << destFile.errorString().toStdString() << std::endl;
            #endif
                    
            return false;
                }

                destFile.write(sourceFile.readAll());

                
            return sourceFile.error() == QFile::NoError && destFile.error()
                        
            == QFile::NoError;
            }

            /**
             * Instantiate a QFile
             * Open the file
             * Access the file through q QDataStream object.
             * 
             * Must ensure that we read all the types in exactly the same order
             * as we wrote them.
             * 
             * If the DataStream is being purely used to read and write basic C++ data types,
             * we dont' even need to call setVersion().
             * 
             * If we want to read or write a file in one go. WE can avoid using QDataStream altogether
             * and instead using QIODevice's write() and readAll() function.
             * For example copy a file.
             
            */
            int main(int argc, char *argv[]) {
                
            //********Write data in to the file.********
                QImage image("Adium.png");
                QMap
            <QString, QColor> map;
                map.insert(
            "red", Qt::red);
                map.insert(
            "green", Qt::green);
                C c(
            23);
                QFile file(
            "data.dat");
                
            if (!file.open(QIODevice::WriteOnly)) {
                    std::cerr 
            << "Cannot open the file: Write." << file.errorString().toStdString() << std::endl;

                    
            return 1;
                }

                QDataStream out(
            &file);
                out.setVersion(QDataStream::Qt_4_3);
                out 
            << quint32(7456<< map << c;
                file.close();

                
            //********Read data from the file.********
                quint32 value;
                QMap
            <QString, QColor> map2;
                C c2;
                
            if (!file.open(QIODevice::ReadOnly)) {
                    std::cerr 
            << "Cannot open the file: Read." << file.errorString().toStdString() << std::endl;

                    
            return 2;
                }
                QDataStream in(
            &file);
                in.setVersion(QDataStream::Qt_4_3);
                in 
            >> value >> map2 >> c2;
                file.close();

                std::cout 
            << value << std::endl << c2.getValue();

                copy(QString(
            "Adium.png"), QString("Copy_Adium.png"));
                
                
            return 0;
            }

            posted on 2008-03-19 00:11 逛奔的蝸牛 閱讀(7357) 評論(0)  編輯 收藏 引用 所屬分類: Qt
            亚洲人成无码www久久久 | 久久久久这里只有精品 | 伊人久久五月天| 精品久久久久一区二区三区| 久久久99精品一区二区| 亚洲国产精品成人久久蜜臀| 色综合久久综合中文综合网| 狠狠久久亚洲欧美专区| 武侠古典久久婷婷狼人伊人| 久久九九精品99国产精品| 欧美综合天天夜夜久久| 狠狠色丁香婷婷久久综合| 无码人妻精品一区二区三区久久久 | 久久精品国产一区| 久久久久综合中文字幕| 国产亚洲精久久久久久无码| 久久亚洲欧洲国产综合| 精品久久香蕉国产线看观看亚洲| 久久久久久国产a免费观看黄色大片 | 狠狠色伊人久久精品综合网| 99精品久久精品一区二区| 99久久综合国产精品二区| 久久久久成人精品无码中文字幕 | 久久久久久无码国产精品中文字幕 | 久久久久久亚洲精品不卡| 久久国产欧美日韩精品| 亚洲AV成人无码久久精品老人| 久久青青草原国产精品免费 | 久久婷婷成人综合色综合| 伊人色综合九久久天天蜜桃| 欧美亚洲日本久久精品| 中文字幕亚洲综合久久| 久久精品成人免费网站| 亚洲国产另类久久久精品| 亚洲v国产v天堂a无码久久| 一级做a爰片久久毛片毛片| 婷婷久久五月天| 精品国产乱码久久久久软件| 亚洲国产成人精品女人久久久 | 99久久无码一区人妻a黑| 人妻精品久久久久中文字幕一冢本|