int main() {
std::deque<std::string> mydeque;
std::back_insert_iterator<decltype(mydeque)> myback_insert_iterator(mydeque);
std::ifstream myifstream("test.txt");
while(std::getline(myifstream, *myback_insert_iterator)) {
}
}
I simply want to read line-wise a text file into a string container.
This produces compiler error:
C2784: could not deduce template argument for ‘std::basic_istream<_Elem,_Traits> &’ from ‘std::ifstream’
What’s wrong?
Try:
If it is one word per line you can simplify to:
If each line contains multiple words and you want to use the back inserter then you need to define a class for reading a whole line in an object that can be used with iterators:
Or we can just use the constructrs: