如何在C++文件中讀取信號時發出EOF信號?我正在編寫一個直接編碼的掃描器,作爲編譯器設計的一部分,它讀入一個文件並將其分割成一個語言的標記。如何在程序打開的文件上發出EOF信號
我要在整個程序中讀取,刪除註釋並壓縮空白。然後把由char生成的程序char放入最大尺寸爲1024個字符的緩衝區中。所以當我們空着的時候,我們會補充緩衝區或者什麼不是。
要打開我有這個寫入的文件:
// Open source file.
source_file.open (filename);
if (source_file.fail()) {
// Failed to open source file.
cerr << "Can't open source file " << *filename << endl;
buffer_fatal_error();
填充緩衝區,我想用while循環和重複像
int i = 0;
// Iterate through the whole file
while(source_file.at(i) != EOF)
{
// If not a tab or newline add to buffer
if (source_file.at(i) != "\n" || source_file.at(i) != "\t")
{
bufferList.add(source_file.at(i));
}
i++;
}
會不會有信號的方式EOF就像我打開的文件那樣?
這或多或少是做什麼的總體綱要。我需要弄清楚一旦空了或者使用雙緩衝時如何補充緩衝區。我還需要弄清楚如何去掉以#
開頭的評論。例如# This is a comment
。我的掃描儀會看到#
,然後刪除所有內容,直到獲得下一個換行符爲止。
EOF表示您只是在文件末尾查找空值 –
嘗試使用'std :: vector'作爲緩衝區,'istream :: read()'將數據讀入緩衝區。 –
@ThomasMatthews將'istream :: read()'去掉空白? – GenericUser01