久久久久久久av_日韩在线中文_看一级毛片视频_日本精品二区_成人深夜福利视频_武道仙尊动漫在线观看

  1. <tfoot id='Zcwir'></tfoot>
    <legend id='Zcwir'><style id='Zcwir'><dir id='Zcwir'><q id='Zcwir'></q></dir></style></legend>
      • <bdo id='Zcwir'></bdo><ul id='Zcwir'></ul>

      <small id='Zcwir'></small><noframes id='Zcwir'>

      <i id='Zcwir'><tr id='Zcwir'><dt id='Zcwir'><q id='Zcwir'><span id='Zcwir'><b id='Zcwir'><form id='Zcwir'><ins id='Zcwir'></ins><ul id='Zcwir'></ul><sub id='Zcwir'></sub></form><legend id='Zcwir'></legend><bdo id='Zcwir'><pre id='Zcwir'><center id='Zcwir'></center></pre></bdo></b><th id='Zcwir'></th></span></q></dt></tr></i><div class="qwawimqqmiuu" id='Zcwir'><tfoot id='Zcwir'></tfoot><dl id='Zcwir'><fieldset id='Zcwir'></fieldset></dl></div>

      C++ 無法讀取文本文件

      C++ Trouble Reading a Text File(C++ 無法讀取文本文件)

        <i id='AwT3b'><tr id='AwT3b'><dt id='AwT3b'><q id='AwT3b'><span id='AwT3b'><b id='AwT3b'><form id='AwT3b'><ins id='AwT3b'></ins><ul id='AwT3b'></ul><sub id='AwT3b'></sub></form><legend id='AwT3b'></legend><bdo id='AwT3b'><pre id='AwT3b'><center id='AwT3b'></center></pre></bdo></b><th id='AwT3b'></th></span></q></dt></tr></i><div class="qwawimqqmiuu" id='AwT3b'><tfoot id='AwT3b'></tfoot><dl id='AwT3b'><fieldset id='AwT3b'></fieldset></dl></div>

            <bdo id='AwT3b'></bdo><ul id='AwT3b'></ul>
                  <tbody id='AwT3b'></tbody>
                <tfoot id='AwT3b'></tfoot>
              • <legend id='AwT3b'><style id='AwT3b'><dir id='AwT3b'><q id='AwT3b'></q></dir></style></legend>

                <small id='AwT3b'></small><noframes id='AwT3b'>

              • 本文介紹了C++ 無法讀取文本文件的處理方法,對大家解決問題具有一定的參考價值,需要的朋友們下面隨著小編來一起學習吧!

                問題描述

                限時送ChatGPT賬號..

                我正在嘗試讀取文本文件,但沒有任何內容.我覺得它可能沒有在我的 Visual Studio Resources 文件夾中正確鏈接,但是如果我雙擊它 - 它在 Visual Studio 中打開得很好,如果我測試它是否打開或者它是否良好,它不會遇到任何問題.該程序現在可以正常編譯,但沒有輸出.我的命令提示符沒有打印任何內容.有什么建議嗎?

                I'm trying to read a text file but nothing is coming out. I feel like maybe It's not linking correctly in my Visual Studio Resources folder but if I double click it - it opens fine in visual studio and it doesn't run into any problems if I test to see if it opens or if it is good. The program compiles fine right now but there's not output. Nothing prints to my command prompt. Any suggestions?

                代碼

                #include <iostream>
                #include <iomanip>
                #include <fstream>
                using namespace std;
                
                int main()
                {
                    char str[100];
                    ifstream test;
                    test.open("test.txt");
                
                    while(test.getline(str, 100, '#'))
                    {
                        cout << str << endl;
                    }
                
                    test.close();
                    return 0;
                }
                

                文本文件

                This is a test Textfile#Read more lines here#and here
                

                推薦答案

                您嘗試按名稱打開沒有路徑的文件,這意味著該文件應在您程序的當前工作目錄中.

                You try to open file by name without path, this means the file shall be in current working directory of your program.

                問題出在從 VS IDE 運行程序時的當前目錄.默認情況下,VS 將運行程序的當前工作目錄設置為項目目錄 $(ProjectDir).但是您的測試文件位于資源目??錄中.所以 open() 函數找不到它,getline() 立即失敗.

                The problem is with current directory when you run your program from VS IDE. VS by default sets current working directory for runnning program to project directory $(ProjectDir). But your test file resides in resources directory. So open() function could not find it and getline() immediately fails.

                解決方案很簡單 - 將您的測試文件復制到項目目錄.或將其復制到目標目錄(創建程序 .exe 文件的位置,通常是 $(ProjectDir)Debug$(ProjectDir)Release>) 并更改 VS IDE 中的工作目錄設置:Project->Properties->Debugging->Working Directory,設置為 $(TargetDir).在這種情況下,它將在 IDE 和命令行/Windows 資源管理器中工作.

                Solution is simple - copy your test file to project directory. Or copy it to target directory (where your program .exe file is created, typically $(ProjectDir)Debug or $(ProjectDir)Release) and change working directory setting in VS IDE: Project->Properties->Debugging->Working Directory, set to $(TargetDir). In this case it will work both from IDE and command line/Windows Explorer.

                另一種可能的解決方案 - 在 open() 調用中設置正確的文件路徑.出于測試/教育目的,您可以對其進行硬編碼,但實際上這不是一種好的軟件開發風格.

                Another possible solution - set correct path to file in your open() call. For testing/education purposes you could hardcode it, but actually this is not good style of software development.

                這篇關于C++ 無法讀取文本文件的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網!

                【網站聲明】本站部分內容來源于互聯網,旨在幫助大家更快的解決問題,如果有圖片或者內容侵犯了您的權益,請聯系我們刪除處理,感謝您的支持!

                相關文檔推薦

                Why do two functions have the same address?(為什么兩個函數的地址相同?)
                Why the initializer of std::function has to be CopyConstructible?(為什么 std::function 的初始化程序必須是可復制構造的?)
                mixing templates with polymorphism(混合模板與多態性)
                When should I use the keyword quot;typenamequot; when using templates(我什么時候應該使用關鍵字“typename?使用模板時)
                Dependent name resolution amp; namespace std / Standard Library(依賴名稱解析命名空間 std/標準庫)
                gcc can compile a variadic template while clang cannot(gcc 可以編譯可變參數模板,而 clang 不能)
                <legend id='PIpTA'><style id='PIpTA'><dir id='PIpTA'><q id='PIpTA'></q></dir></style></legend>
              • <i id='PIpTA'><tr id='PIpTA'><dt id='PIpTA'><q id='PIpTA'><span id='PIpTA'><b id='PIpTA'><form id='PIpTA'><ins id='PIpTA'></ins><ul id='PIpTA'></ul><sub id='PIpTA'></sub></form><legend id='PIpTA'></legend><bdo id='PIpTA'><pre id='PIpTA'><center id='PIpTA'></center></pre></bdo></b><th id='PIpTA'></th></span></q></dt></tr></i><div class="qwawimqqmiuu" id='PIpTA'><tfoot id='PIpTA'></tfoot><dl id='PIpTA'><fieldset id='PIpTA'></fieldset></dl></div>

                        <tbody id='PIpTA'></tbody>
                    • <small id='PIpTA'></small><noframes id='PIpTA'>

                        <tfoot id='PIpTA'></tfoot>
                        • <bdo id='PIpTA'></bdo><ul id='PIpTA'></ul>
                          主站蜘蛛池模板: 夜夜操夜夜爽 | 日韩中文字幕在线播放 | 91三级视频 | 综合伊人| 日韩欧美视频在线 | 免费在线观看毛片 | 亚洲看片| 日本成人小视频 | 五月色综合 | 欧美一级片在线观看 | 久久精品一区二区三区不卡牛牛 | 青青草伊人网 | 四虎com| 日韩av不卡在线 | 日韩视频免费在线观看 | 一级大毛片 | 中文在线字幕免费观看 | 黄色一区二区三区 | 亚洲精品视频一区 | 精品日韩在线 | 日本午夜视频 | 三级网站视频 | 爱福利视频网 | 中文字幕在线观看网站 | 亚洲成人中文字幕 | 伊人综合影院 | 97色在线 | a在线免费观看 | 欧美日韩国产中文 | 欧美大片黄| 欧美激情国产精品 | 天天爱天天色 | 中文字字幕 | 欧美一区二区三区免费 | 美女扒开腿让人桶爽原神 | 中文字幕在线观看不卡 | 欧美日韩一区二区在线观看 | 国产在线欧美 | 超碰97免费| 成人在线a | 欧美一区二区三 |