資源簡介
NULL
博文鏈接:https://cherishlc.iteye.com/blog/2400974

代碼片段和文件信息
#include?
#include?
#include?
#include?
#include?
#include?
#include?“fdstream.hpp“
//using?namespace?std;
using?std::string;
std::shared_ptr?eg_read_from_bash_output(const?char?*cmd)?{
::FILE?*fp?=?::popen(cmd?“r“);
if?(!fp)?{
throw?string(“count?not?open?PIPE“);
}
//boost::fdistream?fs(fileno(fp));?//注意因?yàn)楦割恑stream沒有?operator?=,?不能夠?qū)⒏念愖鳛榉祷刂怠?br/> //如需將fs作為返回值,需使用std::shared_ptr進(jìn)行封裝:?http://en.cppreference.com/w/cpp/memory/shared_ptr/shared_ptr
std::shared_ptr?pfi(new?boost::fdistream(fileno(fp)));
return?pfi;
}
int?main(){
? auto?pfi?=?eg_read_from_bash_output(“cat?hello.txt“);
boost::fdistream&?fs?=?*pfi;?
? string?line;
while?(std::getline(fs?line))?{
std::cout?< }
}
?屬性????????????大小?????日期????時(shí)間???名稱
-----------?---------??----------?-----??----
?????目錄???????????0??2017-11-27?03:47??read_from_bash_output\
?????文件?????????157??2017-11-27?03:31??read_from_bash_output\complie_and_run.sh
?????文件?????????880??2017-11-27?03:47??read_from_bash_output\read_from_bash_output.cpp
?????文件??????????47??2017-11-23?07:22??read_from_bash_output\hello.txt
?????文件????????4292??2017-11-23?07:24??read_from_bash_output\fdstream.hpp
評論
共有 條評論