istream, outstream使用及常見錯誤

2021-09-08 23:11:25 字數 1988 閱讀 7094

使用方法:

使用filebuf開啟檔案,並拷貝給istream/ostream。

如下面的例子中,實現讀取並處理deseq資料夾下所有檔案,輸出到ostream fw.

code:

[cpp]view plain

copy

#include

#include

#include

#include

#include

#include

using namespace std;  

void parsefile(istream& fi, ostream& fo)  

}  void process()  

}  }  

}  int main()  

其中,parsefile的宣告為:void parsefile(istream& fi, ostream& fo)

注意這裡函式宣告必須要加引用,不然會報錯:

錯誤:$ g++ -g test.cpp -o b.out

in file included from /usr/lib/gcc/x86_64-redhat-linux/4.4.6/../../../../include/c++/4.4.6/ios:39,

from /usr/lib/gcc/x86_64-redhat-linux/4.4.6/../../../../include/c++/4.4.6/ostream:40,

from /usr/lib/gcc/x86_64-redhat-linux/4.4.6/../../../../include/c++/4.4.6/iostream:40,

from test.cpp:1:

/usr/lib/gcc/x86_64-redhat-linux/4.4.6/../../../../include/c++/4.4.6/bits/ios_base.h: in copy constructor 'std::basic_ios>::basic_ios(const std::basic_ios>&)':

/usr/lib/gcc/x86_64-redhat-linux/4.4.6/../../../../include/c++/4.4.6/bits/ios_base.h:790: error: 'std::ios_base::ios_base(const std::ios_base&)' is private

/usr/lib/gcc/x86_64-redhat-linux/4.4.6/../../../../include/c++/4.4.6/iosfwd:47: error: within this context

/usr/lib/gcc/x86_64-redhat-linux/4.4.6/../../../../include/c++/4.4.6/iosfwd: in copy constructor 'std::basic_istream>::basic_istream(const std::basic_istream>&)':

/usr/lib/gcc/x86_64-redhat-linux/4.4.6/../../../../include/c++/4.4.6/iosfwd:53: note: synthesized method 'std::basic_ios>::basic_ios(const std::basic_ios>&)' first required here 

test.cpp: in function 'void process()':

test.cpp:24: note: synthesized method 'std::basic_istream>::basic_istream(const std::basic_istream>&)' first required here 

test.cpp:24: error:   initializing argument 1 of 'void parsefile(std::istream, std::ostream)'

原因是stream型別資料不支援拷貝,所以必須傳址。

參考:from: 

使用PyCharm編譯python常見錯誤

1 bs4.featurenotfound couldn t find a tree builder with the features you requested html parser.do you need to install a parser library?處理 1 修改bs4的版本 2...

Export Import 使用技巧與常見錯誤

export 和 import 是一對讀寫oracle資料的工具.export 將 oracle 資料庫中的資料輸出到作業系統檔案中,import 把這些檔案中的資料讀到oracle 資料庫中.export import可以用來完成以下工作 資料歸檔,資料庫公升級,備份資料庫,把資料從乙個資料庫移到...

Python程式設計 Django入門及常見錯誤

django官網 開發工具 pycharm 段落 p 列表 ul,ol,li 換行 br 連線 a 容器 div,span img table,tr,td 表單 input pip install django 安裝 python m django version 檢視版本號 django admi...