I’ve just encountered an problem today: The following code seems to work in MSVC++ 2010 but not with Clang LLVM 4.1 (with GNU++11).
#include <fstream>
void foo(std::fstream& file){
file << "foo";
}
int main() {
std::fstream dummy("dummy");
foo(dummy);
return 0;
}
generates
Invalid operands to binary expression (std::fstream (aka basic_fstream<char>) and const char[4])
on Clang. I thought passing iostream arguments by reference would be common practice in C++. I’m not even sure if this is related to clang, C++11 or anything else.
Any idea how I can pass streams to functions then?
I assume that your original code (that you only partially posted in your original question) looked something like this:
Indeed, this gives the following error message with clang++ 3.2
Unfortunately, you only posted the first error message but not the second.
From the second error message, it is obvious that you only
#include <iosfwd>but not#include <fstream>. If you fix that, everything will be OK.Please post both the complete code and all the error messages next time.