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

            eryar

            PipeCAD - Plant Piping Design Software.
            RvmTranslator - Translate AVEVA RVM to OBJ, glTF, etc.
            posts - 603, comments - 590, trackbacks - 0, articles - 0

            std::ofstream failed

            Posted on 2014-07-12 15:55 eryar 閱讀(3792) 評(píng)論(3)  編輯 收藏 引用 所屬分類: 6.Others

            今天在輸出數(shù)據(jù)到文件時(shí),用到C++的std::ofstream,結(jié)果文件就是沒有輸出成功,示例程序如下所示:


            #include 
            <fstream>
            #include 
            <sstream>
            #include 
            <iostream>
            #include 
            <cassert>

            void Output(const std::string &theFileName)
            {
                std::ofstream os(theFileName.c_str());

                assert(os.good());

                os 
            << "Just for test" << std::endl;

                os.close();
            }

            int main(int argc, char* argv[])
            {
                std::stringstream ss;

                
            // remove the std::endl
                ss << "test" << 1 << ".txt" << std::endl;

                Output(ss.str());

                
            return 0;
            }

             

            最后才發(fā)現(xiàn)是文件名有問題,修改程序,去掉生成文件名的一個(gè)std::endl即可:

             


            #include 
            <fstream>
            #include 
            <sstream>
            #include 
            <iostream>
            #include 
            <cassert>

            void Output(const std::string &theFileName)
            {
                std::ofstream os(theFileName.c_str());

                assert(os.good());

                os 
            << "Just for test" << std::endl;

                os.close();
            }

            int main(int argc, char* argv[])
            {
                std::stringstream ss;

                
            // remove the std::endl
                ss << "test" << 1 << ".txt";

                Output(ss.str());

                
            return 0;
            }


            不經(jīng)意間就會(huì)寫出這種小錯(cuò)誤的代碼,而且找錯(cuò)很很費(fèi)時(shí)。

            Feedback

            # re: std::ofstream failed  回復(fù)  更多評(píng)論   

            2014-07-14 00:36 by pdb.so
            多看書,多調(diào)試

            # re: std::ofstream failed  回復(fù)  更多評(píng)論   

            2014-07-22 17:17 by 云騰
            文件名不允許存在特殊字符 www.cppentry.com

            # re: std::ofstream failed  回復(fù)  更多評(píng)論   

            2014-07-22 18:38 by eryar
            是的。
            加上assert()會(huì)更好點(diǎn)
            @云騰
            久久婷婷五月综合色奶水99啪| 少妇高潮惨叫久久久久久| 色成年激情久久综合| 伊人久久精品线影院| 久久久久久久91精品免费观看| 人妻无码久久精品| 欧美亚洲国产精品久久久久| 精品国产99久久久久久麻豆| 国产午夜福利精品久久2021 | AV无码久久久久不卡网站下载| 国产精品免费福利久久| 亚洲国产精品无码久久九九| 欧美黑人又粗又大久久久| 久久久久国产亚洲AV麻豆| 99精品久久精品一区二区| 精品久久久久久99人妻| 99久久精品国产一区二区 | 久久精品亚洲精品国产色婷| 精品人妻伦九区久久AAA片69| 99久久国产宗和精品1上映 | 久久超碰97人人做人人爱| 欧美麻豆久久久久久中文| 久久99久久99小草精品免视看| 国产精品一区二区久久精品涩爱| 久久精品一区二区| 精品国际久久久久999波多野| 性做久久久久久久久浪潮| 国产精品熟女福利久久AV| 日本精品久久久中文字幕| 亚洲香蕉网久久综合影视| 狠狠综合久久AV一区二区三区| 看全色黄大色大片免费久久久| 国产精品青草久久久久福利99| 91超碰碰碰碰久久久久久综合| 91精品国产综合久久久久久| 久久人人爽人人爽人人片AV不| 亚洲精品乱码久久久久久久久久久久| 一级a性色生活片久久无| 人妻无码αv中文字幕久久琪琪布| 欧美国产精品久久高清| 亚洲欧美久久久久9999 |