• <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>

            積木

            No sub title

              C++博客 :: 首頁 :: 聯(lián)系 :: 聚合  :: 管理
              140 Posts :: 1 Stories :: 11 Comments :: 0 Trackbacks

            常用鏈接

            留言簿(1)

            我參與的團(tuán)隊

            搜索

            •  

            最新評論

            閱讀排行榜

            評論排行榜

            // FileOp.cpp : Defines the entry point for the console application.
            //

            #include 
            "stdafx.h"

            //要用ifstream與ofstream進(jìn)行文件的輸入與輸出操作,必須包含此頭文件
            #include <fstream>
            #include 
            <iostream>
            #include 
            <stdio.h>//FILE需要



            int _tmain(int argc, _TCHAR* argv[])
            {
                
            //技術(shù)扶自: http://www.mini188.com/showtopic-954.aspx

            /************************************************************************/
            /** 輸入文件流 ofstream
            /***********************************************************************
            */
                
            /*
                //聲明文件輸入的操作對象(輸出流對象)
                std::ofstream fout;
                //打開一個文件,提示:如果Output.txt文件不存在,則系統(tǒng)會自動為你創(chuàng)建一個
                fout.open("Output.txt");
                //對文件進(jìn)行寫操作。
                fout << "This is a first line." << "\n";
                fout << "This is a second line." << "\n";
                
                int num = 150;
                char name[] = "John Doe";
                fout << "Here is a number: " << num << "\n";
                fout << "Now here is a string: " << name << "\n";

                //將文件流內(nèi)容保存到硬盤
                fout.flush();
                //關(guān)閉文件流
                fout.close();
                
            */


            /************************************************************************/
            /** 輸入文件流 ifstream  12 GameDev 15.45 L This is really awesome!
            /***********************************************************************
            */
                
            /*
                std::ifstream fin("Input.txt");
                
                int number;
                float real;
                char letter, word[8];
                fin >> number >> word >> real >> letter;
                char sentence[1000];
                fin.getline(sentence, 1000);

                fin.close();
                
            */


            /************************************************************************/
            /** 文件流操作 fstream
            /***********************************************************************
            */
            //     std::fstream fFile;
            //     fFile.open("Output.txt", std::ios::in | std::ios::out);
                
            //fFile.open("無線iPhone平臺開發(fā)基礎(chǔ)培訓(xùn)交流圈.jpg");    //經(jīng)測試,非文本文件資源是打不開的。
                
                
            //將整個文件的內(nèi)容讀取出來,并顯示
                
            //注意:用這種方法讀出來的,都是忽略空格與換行符的
            //     if (fFile.is_open())
            //     {
            //         char letter;
            //         //while (fFile.good() && !fFile.eof())
            //         while (!fFile.eof())    //用這個與上面那個都是一樣的效果
            //         {
            //             fFile >> letter;
            //             if (fFile.eof())
            //                 break;
            //             std::cout << letter << std::endl;
            //         }
            //         getchar();
            //     }


                
            //注意:用這種方法讀限出來的,都是沒忽略末尾的換行符的
            //     if (fFile.is_open())
            //     {
            //         char line[2048];    
            //         while (fFile.good() && !fFile.eof())
            //         {
            //             fFile.getline(line, 2048);
            //             static int count = 0;
            //             if (count < 3)
            //             {
            //                 count += 1;
            //                 fFile.seekg(0, std::ios::beg);    //這個是改變讀的指針位置。如果是想改變寫的指針位置用fFile.seekp(0, std::ios::beg/end);
            //             }
            //             std::cout << line << std::endl;
            //         }
            // 
            //         //將第一行的字符串改:"The first line string is changed."
            //         fFile.seekp(0, std::ios::beg);
            //         //fFile << "The first line string is changed.";    //寫內(nèi)容不是這樣寫的。如果是ofstream可以這么寫。但對于fstream需要用下面的方法來寫。測試結(jié)果發(fā)現(xiàn),仍是寫不進(jìn)去
            //         //char* pszTempForWrite = "The first line string is changed.";
            //         //fFile.write(pszTempForWrite, strlen(pszTempForWrite));
            //         fFile.seekg(0, std::ios::beg);
            //         fFile.getline(line, 2048);
            //         std::cout << line << std::endl;
            //         getchar();
            //     }

            //     //* fstream的其他一些方法
            //     //read方法
            //     char* pszOutputFileText = NULL;
            //     fFile.seekg(0, std::ios::end);
            //     int nSize;
            //     nSize = fFile.tellg();
            //     //std::cout << fFile.tellg() << std::endl;
            //     //用read方法一次性將整文件給讀取出來(注意:這些讀出來后,末性居然會帶了一個亂碼。這個郁悶。)
            //     pszOutputFileText = new char[nSize + 1];
            //     fFile.seekg(0, std::ios::beg);
            //     fFile.read(pszOutputFileText, nSize);
            //     pszOutputFileText[nSize] = '\0';
            //     std::cout << pszOutputFileText << std::endl;
            //     delete [] pszOutputFileText;
            //     getchar();
            // 
            //     fFile.close();


            /************************************************************************/
            /** 二進(jìn)制文件的讀寫
            /***********************************************************************
            */


            /************************************************************************/
            /** 字符串長度
            /***********************************************************************
            */
            //     char* pszString = "Hello";
            //     std::cout << strlen(pszString) << std::endl;    //輸出5
            // 
            //     std::string sString = "Hello";
            //     std::cout << strlen(sString.c_str()) << std::endl;//輸出5
            // 
            //     char szTest[5] = { 'H', 'e', 'l', 'l', 'o' };
            //     std::cout << szTest[5] << std::endl;    //越界了,所以會報。
            //     getchar();


            /************************************************************************/
            /** 使用FILE類對文件進(jìn)行操作 (FILE在stdio.h中
            /***********************************************************************
            */
                FILE
            * materialFile = fopen("DefaultObjectStd.material""r");
                
            if (materialFile == NULL)
                {
                    std::cout 
            << "Open the file \"DefaultObjectStd.material\" failure." << std::endl;
                    
            return 0;
                }

                
            const int MAX_COUNT =2048;
                
            char everyline[MAX_COUNT] = { '\0' };
                
            while (fgets(everyline, MAX_COUNT, materialFile))
                {
                    std::cout 
            << everyline;    //注意:通過fgets()函數(shù)讀取出來的定符串,末尾是帶有換行符的。這與上面的是不一樣的。
                }

                
            //取得文件的長度(即:文件的大小)
                int nMaterialFileSize;
                fseek(materialFile, 
            0, SEEK_END);
                nMaterialFileSize 
            = ftell(materialFile);
                std::cout 
            << std::endl << nMaterialFileSize << std::endl;
                
                getchar();

                fclose(materialFile);
                

                
            return 0;
            }
            posted on 2011-06-27 18:21 Jacc.Kim 閱讀(818) 評論(0)  編輯 收藏 引用 所屬分類: VC / C++
            日韩AV毛片精品久久久| 99久久99久久精品国产片| 国产—久久香蕉国产线看观看| 久久久亚洲裙底偷窥综合| 久久无码av三级| 93精91精品国产综合久久香蕉 | 久久一区二区三区99| 99re这里只有精品热久久| 久久99精品久久久久婷婷| 色婷婷综合久久久中文字幕| 三级韩国一区久久二区综合| 亚洲精品无码专区久久同性男| 青草久久久国产线免观| 婷婷久久综合九色综合九七| 欧美大战日韩91综合一区婷婷久久青草| 国产精品热久久毛片| 国产免费福利体检区久久| 久久久久黑人强伦姧人妻| 久久久久久久综合日本| 国产99久久久国产精品小说| 一级a性色生活片久久无| 久久精品极品盛宴观看| 午夜精品久久久久久99热| 国产精品久久久久久影院| 国产精品久久久久久久午夜片| 久久久久久精品久久久久| 人妻少妇久久中文字幕| 久久这里只精品国产99热| 四虎影视久久久免费| 无码国内精品久久综合88| 久久国产精品99国产精| 久久丝袜精品中文字幕| 久久综合狠狠综合久久| 99久久精品免费观看国产| 久久精品国产亚洲AV不卡| 91精品国产9l久久久久| 99久久国产亚洲综合精品| 久久电影网一区| 亚洲av日韩精品久久久久久a| 久久久久久极精品久久久| 久久久久高潮毛片免费全部播放 |