• <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>
            posts - 29,comments - 10,trackbacks - 0
            1、 格式化輸出:

            1) width()函數(shù):可以為接下來的所有顯示要素指定默認(rèn)的寬度。

            2) setw()函數(shù):設(shè)置數(shù)據(jù)項實用的寬度

            3) fill()函數(shù):當(dāng)輸入寬度非默認(rèn)寬度時可以設(shè)置填充字符的值

            4) setiosflags(ios::left)函數(shù):表示輸出值的對其方式

            5) dechexoct本別表示十進制、十六進制和八進制

            6) put:把單個字符寫入輸入流中

            7) get:類似于提取運算符>>,知識空字符被包含到輸入中。

            #include <iostream>

            #include 
            <iomanip>

            using namespace std;
            int main()

            {

                   cout.width(
            10);

                   cout
            <<setiosflags(ios::left)<<oct<<25<<endl;

                   cout.width(
            10);

                   cout
            <<setiosflags(ios::right)<<hex<<25<<endl;

                   cout
            <<dec<<setfill('b')<<setw(10);

                   cout
            <<1024<<"OK"<<endl;

                   cout.put(
            'H'); 

                
            return 0;

            }

            #include <iostream>

            int main()
            {
                
            char line[25], ch = 0*cp;

                std::cout 
            << " Type a line terminated by 'x'"
                          
            << std::endl << '>';
                cp 
            = line;
                
            while (ch != 'x')
                {
                    std::cin 
            >> ch;
                    
            *cp++ = ch;
                }
                
            *cp = '\0';
                std::cout 
            << ' ' << line;

                std::cout 
            << "\n Type another one" << std::endl << '>';
                cp 
            = line;
                ch 
            = 0;
                
            while (ch != 'x')
                {
                    std::cin.
            get(ch);
                    
            *cp++ = ch;
                }
                
            *cp = '\0';
                std::cout 
            << ' ' << line;
                
                
            return 0;
            }

            2、 文件輸入/輸出

            1)ofstream類:文件輸出

            #include <fstream>
            #include 
            <iostream>

            int main()
            {
                std::cout 
            << "Opening file" << std::endl;
                std::ofstream tfile(
            "test.dat", std::ios::app);

                std::cout 
            << "Writing to file" << std::endl;
                tfile 
            << ", and these are more";

                
            return 0;
            }
            標(biāo)志 描述
            app 把所有的新數(shù)據(jù)寫到文件尾部
            ate 把所有的新數(shù)據(jù)寫到文件尾部,如果程序移動了文件指針,就把數(shù)據(jù)寫到當(dāng)前位置
            binary 以二進制模式而不是文本模式打開文件
            out    打開由于輸出的文件,刪除文件的當(dāng)前內(nèi)容。該模式只在沒有指定文件打開模式時使用
            trunc  打開用于輸出的文件,刪除文件的當(dāng)前內(nèi)容
                  相關(guān)函數(shù):
            函數(shù) 描述
            attach() 把打開的文件與流關(guān)聯(lián)
            close() 在刷新未保存的數(shù)據(jù)后關(guān)閉文件
            flush() 刷新流
            open() 打開一個文件并把它與流關(guān)聯(lián)
            put() 向流中寫入一個字符
            rdbuf() 返回與流關(guān)聯(lián)的filebuf對象
            seekp() 設(shè)置流文件指針的位置
            setmode() 把流設(shè)置成二進制模式或文本模式
            tellp() 獲取流文件指針的位置
            write() 向流中寫入一組字節(jié)

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


            int main() 
            {     
                std::
            string str("This is a test");
                
                
            // Create an output stream object.
                std::ofstream tfile;
                
                
            // Associate a file with the stream.
                tfile.open("testfile.txt");
                
                
            // Write a string one character at a time.
                for (int x=0; x<14++x)
                
            {
                    std::cout 
            << "File pointer: " << tfile.tellp();
                    tfile.put(str[x]);
                    std::cout 
            << "  " << str[x] << std::endl;
                }

                
                
            return 0;
            }


            2)ifstream類:輸出類
                  相關(guān)函數(shù)
            eof() 測試文件是否結(jié)束
            seekg() 在文件中定位,有beg、cur和end表示起始位置,seekg(5,ios::cur)
            tellg() 指示在文件中的位置
            #include <fstream>
            #include 
            <iostream>

            int main()
            {
                std::ifstream tfile(
            "test.dat");
                tfile.seekg(
            6);        // Seek six characters in

                
            while (!tfile.eof())
                {
                    
            char ch;
                    tfile.
            get(ch);
                    
            if (!tfile.eof())
                        std::cout 
            << ch;
                }

                
            return 0;
            }
            3)文件的輸入輸出
            #include <fstream>
            #include 
            <cctype>
            #include 
            <iostream>

            int main()
            {
                
            char* fname = "test.dat";

                
            // Read the file into an array.
                std::ifstream tfile(fname, std::ios::in |
                    std::ios::
            out | std::ios::binary);
                std::ostream ofile(tfile.rdbuf());
                
            char tdata[100];
                
            int i = 0;
                
            while (!tfile.eof() && i < sizeof tdata)
                    tfile.
            get(tdata[i++]);

                
            // Write the array to the file.
                ofile.seekp(0, std::ios::end);
                ofile 
            << "\r\n";
                
            for (int j = 0; j < i-1; j++)
                    ofile.put(static_cast
            <char>(toupper(tdata[j])));
                
                
            return 0;
            }
            posted on 2009-06-22 09:16 The_Moment 閱讀(562) 評論(0)  編輯 收藏 引用 所屬分類: C\C++
            久久精品国产免费观看| 亚洲国产成人精品女人久久久| 久久成人18免费网站| 青青草国产成人久久91网| 精品久久久久久亚洲| 久久精品国产91久久麻豆自制| 久久精品国产网红主播| 国产精品久久久久国产A级| 久久国产精品77777| 伊人热人久久中文字幕| 久久久久无码精品| 成人午夜精品无码区久久| 国产精品美女久久久久网| 国产成人久久精品二区三区| 久久精品国产精品亜洲毛片| 久久综合偷偷噜噜噜色| 久久久久亚洲AV无码永不| 国产精品永久久久久久久久久| 久久亚洲精品国产亚洲老地址 | 色综合久久综合中文综合网| 午夜久久久久久禁播电影| 久久精品国产精品亚洲精品| 久久综合九色综合久99| 潮喷大喷水系列无码久久精品| 94久久国产乱子伦精品免费 | 久久午夜羞羞影院免费观看| 国产成人综合久久精品尤物| 亚洲性久久久影院| 91久久九九无码成人网站| 伊人久久大香线蕉AV色婷婷色| 国产精品久久久久久影院 | 久久精品日日躁夜夜躁欧美| 久久综合九色综合欧美狠狠| 精产国品久久一二三产区区别| 久久婷婷国产麻豆91天堂| 亚洲精品国产美女久久久| 亚洲国产精品综合久久网络| 国产叼嘿久久精品久久| 狠狠色丁香久久综合婷婷| 国产情侣久久久久aⅴ免费| 一本色道久久99一综合|