I am using g ++ to compile some code. I wrote the following snippet:
bool WriteAccess = true; string Name = "my_file.txt"; ofstream File; ios_base::open_mode Mode = std::ios_base::in | std::ios_base::binary; if(WriteAccess) Mode |= std::ios_base::out | std::ios_base::trunc; File.open(Name.data(), Mode);
And I get these errors ... any idea why?
Error 1: invalid conversion from 'int to' std :: _ Ios_Openmode
Error 2: initialization of argument 2 from 'std :: basic_filebuf <_CharT, _Traits> * std :: basic_filebuf <_CharT, _Traits> :: open (const char *, std :: _ Ios_Openmode) [with _CharT = char, _Traits = std :: char_traits]
As far as I can tell from a Google search, g ++ actually violates the C ++ standard. Which I find quite surprising, since they are generally very strictly in line with the standard. This is true? Or am I doing something wrong.
My reference for the standard: http://www.cplusplus.com/reference/iostream/ofstream/open/
source share