Reputation: 4060
I'm trying to overwrite the lines of a file and take out the word "hello". For some reason this isn't working. This is the file:
out.txt:
hello
1
2
goodbye
Here are the errors:
error: no matching function for call to
'std::istream_iterator<std::basic_string<char, std::char_traits<char>, std::allocator<char> >, char, std::char_traits<char>, int>::istream_iterator(std::fstream)'|
#include <fstream>
#include <string>
#include <algorithm>
#include <iterator>
int main()
{
std::copy_if(
std::istream_iterator<std::string>(std::fstream("out.txt")),
std::istream_iterator<std::string>(),
std::istream_iterator<std::string>(std::fstream("out.txt")),
[] (std::string str) { return str != "hello"; }
);
}
Upvotes: 0
Views: 414
Reputation: 33651
Look at available constructors for std::istream_iterator
:
istream_iterator();
constexpr istream_iterator();
istream_iterator( istream_type& stream );
istream_iterator( const istream_iterator& other ) = default;
You're trying to call third constructor, but you pass a rvalue, while a lvalie is expected.
Upvotes: 4