[英]read sequence of hex values from ifstream using std::copy
考慮一個包含以十六進制表示法表示的整數序列的文件。 我可以像這樣流式傳輸它們:
using namespace std;
ifstream infile(fname);
unsigned int i;
vector<unsigned int> vals;
while (infile >> std::hex >> i){
vals.push_back(i);
}
如果我想用istream_iterator
做同樣的事情怎么辦?
/// borks on hex:
copy(istream_iterator<unsigned int>(infile),
istream_iterator<unsigned int>(), back_inserter(ref_data));
有沒有辦法告訴istream_iterator
如何假設十六進制表示法?
同樣的方式:
copy(istream_iterator<unsigned int>(infile >> std::hex),
istream_iterator<unsigned int>(),
back_inserter(ref_data));
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.