#include <iostream>
#include <fstream>
#include <string>
#include <vector>
#include <algorithm>
using namespace std;
int main()
{
ifstream fin("test.txt");
vector<string> coll;
typedef istreambuf_iterator<char> IStrBufIter;
copy(IStrBufIter(fin), IStrBufIter(), back_inserter(coll)); // Error! Why?
}
该问题在代码中进行了注释。
我得到的错误是:
oi.cpp:15:62: required from here
error: invalid user-defined conversion from ‘std::istreambuf_iterator<char, std::char_traits<char> >::char_type {aka char}’ to ‘std::vector<std::basic_string<char> >::const_reference {aka const std::basic_string<char>&}’ [-fpermissive]
随后的错误消息太多,无法粘贴到此处。请参阅 gcc 4.7 上的错误消息http://pastebin.com/anKQqL00