Below code does not work and give the compilation error of:
Severity Code Description Project File Line Suppression State Error invalid operands to binary expression ('std::wofstream' (aka 'basic_ofstream >'))
And the code is:
template <class T>
void printtofile(std::string filename, int mode, T var, std::wstring msg)
{
wofstream outfile;
if (mode == 0) outfile.open(filename); else outfile.open(filename, ios::out | ios::app);
outfile << msg << L"\n";
outfile << var << L"\n";
outfile.close();
}
If I comment out the below line there is no error.
outfile << var << L"\n";
Okay. The weird and confusing thing is that If I add the function with different parameters as the following there is no error although I do not comment out the line I mentioned above:
template <class T>
void printtofile(std::string filename, int mode, T var)
{
wofstream outfile;
if (mode == 0) outfile.open(filename); else outfile.open(filename, ios::out | ios::app);
outfile << var << L"\n";
outfile.close();
}
Isn't this the same thing? What is going on here?