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

            C++文件操作

             

            #include <iostream>
            #include 
            <fstream>
            #include 
            <string>

            using namespace std;

            int main()
            {
                
            const char filename[] = "mytext.txt";
                ofstream o_file;
                ifstream i_file;
                
            string out_text;

                
            //
                o_file.open(filename);
                
            for (int i = 1; i <= 10; i++)
                
            {
                    o_file 
            << "" << i << ""<<endl; //將內(nèi)容寫入到文本文件中
                }

                o_file.close();

                
            //
                i_file.open(filename);
                
            if (i_file.is_open())
                
            {
                    
            while (i_file.good())
                    
            {
                        i_file
            >> out_text; //將讀取的內(nèi)容存儲(chǔ)到變量out_text中
                        cout << out_text << endl; //在控制臺(tái)輸出讀取的內(nèi)容。為什么最后一行的內(nèi)容會(huì)出現(xiàn)兩次
                    }

                }

                
            else
                    cout 
            << "打開文件:" << filename << " 時(shí)出錯(cuò)!";
                i_file.close();

                system(
            "PAUSE");
                
            return 0;
            }



            preheader:
            #include "stdafx.h"
            #include 
            <iostream>
            #include 
            <fstream>
            #include 
            <string>
            using namespace std;

            int _tmain(int argc, _TCHAR* argv[])
            {
                
            const char filename[]="test.doc";
                ofstream o_file;
            /* 輸出流:將數(shù)據(jù)從內(nèi)存輸出其中ofstream是將數(shù)據(jù)輸出到文件,因此對(duì)于文件來說是“寫”*/
                ifstream i_file;
            /*將數(shù)據(jù)輸入到內(nèi)存,其中ifstream是說輸入的數(shù)據(jù)在文件中,因此對(duì)于文件來說是“讀”*/
                
            string out_text;

                
            //
                o_file.open(filename);
                
            for(int i =0;i<=12;i++)
                
            {
                    o_file
            <<""<<i<<"行\(zhòng)n";//將內(nèi)容寫入文本
                }

                o_file.close();
                
            //
                i_file.open(filename);
                
            if(i_file.is_open())
                
            {
                    
            while(i_file>>out_text)
                    
            {
                        cout 
            << out_text << endl;
                    }

                }

                
            else
                    cout
            <<"打開文件:"<<filename<<"時(shí)出錯(cuò)!";
                i_file.close();
                system(
            "PAUSE");

                
            return 0;
            }
             

            posted on 2010-05-28 09:46 lhking 閱讀(254) 評(píng)論(0)  編輯 收藏 引用


            只有注冊(cè)用戶登錄后才能發(fā)表評(píng)論。
            網(wǎng)站導(dǎo)航: 博客園   IT新聞   BlogJava   博問   Chat2DB   管理


            導(dǎo)航

            <2010年5月>
            2526272829301
            2345678
            9101112131415
            16171819202122
            23242526272829
            303112345

            統(tǒng)計(jì)

            常用鏈接

            留言簿

            隨筆檔案

            搜索

            最新評(píng)論

            閱讀排行榜

            評(píng)論排行榜

            国产精品久久久久国产A级| 性做久久久久久久久久久| 久久99国产综合精品女同| 久久九九有精品国产23百花影院| 色综合久久最新中文字幕| 色偷偷91久久综合噜噜噜噜| 久久久久亚洲AV片无码下载蜜桃| 99久久国语露脸精品国产| 久久久久亚洲AV综合波多野结衣| 无码人妻久久久一区二区三区| 伊人色综合久久天天| 狠狠色丁香久久婷婷综合| 免费国产99久久久香蕉| 伊人久久成人成综合网222| 国产精品久久网| 色综合久久久久无码专区| 久久久亚洲精品蜜桃臀| 97久久超碰国产精品旧版| 欧美伊人久久大香线蕉综合| 久久精品国产亚洲一区二区三区| 久久精品亚洲精品国产色婷| 久久AV无码精品人妻糸列| 中文成人久久久久影院免费观看| 久久精品国产福利国产秒| 亚洲va中文字幕无码久久| 亚洲?V乱码久久精品蜜桃| 国产成人99久久亚洲综合精品| 欧美一区二区三区久久综合| 久久精品国产亚洲AV香蕉| 亚洲欧美国产精品专区久久| 久久国产热这里只有精品| 国产精品免费看久久久香蕉| 久久久中文字幕| 久久美女人爽女人爽| 久久综合久久综合久久综合| 久久国产精品久久精品国产| 97久久国产亚洲精品超碰热| 久久久久国产精品| 国产精品丝袜久久久久久不卡| 国产精品日韩欧美久久综合| 欧美午夜A∨大片久久 |