![](/img/trans.png)
[英]How to read strings with spaces from a ifstream using istream_iterator?
[英]Get istream_iterator from ifstream
我試圖從ifstream
獲取istream
迭代器,但失敗了......
void Test_CH_3_1::set_up()
{
std::ifstream file_in("makefile-dependencies.dat");
typedef boost::graph_traits<Graph>::vertices_size_type size_type;
size_type n_vertices;
file_in >> n_vertices; // read in number of vertices
if (file_in)
{
std::cout << n_vertices << std::endl;
}
std::istream_iterator<std::pair<size_type, size_type> > input_begin, input_end;
input_begin=std::istream_iterator<std::pair<size_type, size_type> >(file_in);
g_ = Graph(input_begin, input_end, n_vertices);
}
我得到以下錯誤:
no match for "operator>>" (operand types are std::istream_iterator<std::pair<long unsigned int, long unsigned int> >::istream_type {aka std::basic_istream<char> and std::pair<long unsigned int, long unsigned int>)
錯誤信息非常清楚。 沒有為從std::istream
讀取std::pair
定義operator>>
。 在您的應用程序代碼中定義一個,一切都應該很好。
std::istream& operator>>(std::istream& in, std::pair<std::size_type, std::size_type>& p)
{
return in >> p.first >> p.second;
}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.