這個項目在C++中。我試圖沿着一個文本文件移動,並在屏幕上每次打印80個字符的substr。下一步將是更新x的開始位置,然後再次打印。我的目標是通過txt「滑動」。當我開始第二個流操作時,我沒有收到錯誤,但屏幕上沒有輸出任何文本。 任何知道我在做什麼錯的人?在執行新操作之前是否必須關閉文件? ThanxC++將txt讀入字符串錯誤
ifstream ifs("data.txt");
string line;
string subline;
int x=5;
while(getline(ifs,line)) {
subline=line.substr(x,80);
cout << subline;
}
system("pause");
system("cls");
x++;
//my issue!
while(getline(ifs,line)) {
subline=line.substr(x,80);
cout << subline;
}
你確實應該嘗試學會與你的IDE /調試器調試應用程序。你在用什麼IDE? – Constantinius
代碼塊。它並沒有提到任何錯誤。 根據記錄:我用 的#include 的#include 的#include 的#include 使用命名空間std; –
Rps
我不是指編譯bug。使用調試器,您可以瀏覽應用程序,檢查其路徑,分析變量等。查看此URL:http://wiki.codeblocks.org/index.php?title=Debugging_with_Code:Blocks – Constantinius