Because without parentheses, the compiler treats this as a function declaration, declaring a function called content that returns std::string and takes as arguments a std::istreambuf_iterator<char> with the name ifs and an alias that is a function that takes no arguments, returning a std::istreambuf_iterator<char> .
You can either live with partners, or as Alexanderβs notes in the comments, you can use a single C ++ initialization function that does not have such ambiguities:
std::string content { std::istreambuf_iterator<char>(ifs), std::istreambuf_iterator<char>() };
Or as Loki mentions:
std::string content = std::string(std::istreambuf_iterator<char>(ifs), std::istreambuf_iterator<char>());
Seth carnegie
source share