I was getting some help on creating files with fstream, but came across this method where you pass std::fstream::trunc to the constructor.
I was curious as to how fstream is a class, but referencing the trunc member is like fstream is a namespace (fstream::trunc, like NAMESPACE::MEMBER).
How is this done?
truncis a static member of the classstd::ios_base. To access static members you need to use the class name where they are declared or an object of the class.Here is a demonstration program
The program output is
Or you could declare the static data member like for example
or
Or you could declare it within the class like
and then define it outside the class like