Yes, you can. That’s the point in the OO concept called subtype polymorphism. Since ofstream
derives from ostream
, every instance of ofstream
is at the same time an instance of ostream
too (conceptually). So you can use it wherever an instance of ostream
is expected.
Related Posts:
- Read file line by line using ifstream in C++
- Read file line by line using ifstream in C++
- “Incomplete type not allowed ” when creating std::ofstream objects
- Sleep for milliseconds
- C++ Cout & Cin & System “Ambiguous” [closed]
- Floating point exception( core dump
- Passing Arrays to Function in C++
- Return array in a function
- Regular cast vs. static_cast vs. dynamic_cast
- What is an unsigned char?
- C++ std::priority_queue uses the lambda expression
- How can I clear console
- How to go from fopen to fopen_s
- How does the modulus operator work?
- Single class has a Class Redefinition Error
- Identifier not found error on function call
- Debug assertion failed. C++ vector subscript out of range
- What causes a SIGABRT fault?
- Graphics Library for C++
- ‘cout’ was not declared in this scope
- What is the difference between const int*, const int * const, and int const *?
- what does “error : a nonstatic member reference must be relative to a specific object” mean?
- “Symbol(s) not found for architecture x86_64” on QtCreator project
- Socket Programming in C++
- warning: ISO C++ forbids variable length array
- cin >> “no operator matches these operands”
- C++ Structure Initialization
- expression preceding parentheses of apparent call must have (pointer-to-) function type
- Enum to String C++
- Random float number generation
- C++ terminate called without an active exception
- MinGW: “gcc is not recognized as an internal or external command”
- Convert Python program to C/C++ code?
- What does the assignment of ~0u to a variable mean in C++?
- expected expression in C++?
- How to access the contents of a vector from a pointer to the vector in C++?
- printf with std::string?
- “Error: expression must have a pointer type” when using the “this” keyword
- C++ #include guards
- glm rotate usage in Opengl
- warning: control reaches end of non-void function [-Wreturn-type]
- Program received signal SIGSEGV, Segmentation fault
- How can I iterate through a string and also know the index (current position)?
- c++ parse int from string [duplicate]
- C++ array assign error: invalid array assignment
- Is there a median function in the C++ library?
- Determine if map contains a value for a key?
- error: member access into incomplete type : forward declaration of
- Debug assertion failed
- “Implicit instantiation of undefined template” when forward declaring template class
- “…redeclared as different kind of symbol”?
- Error “system” is ambiguous?
- expected identifier before string constant
- C++ error: expected identifier before “(” token
- Function for C++ struct
- C++ error: double free or corruption (fasttop)
- no match for ‘operator<<’ in ‘std::operator
- android,
android-layout,
android-linearlayout,
gradient, - Reading multiple lines from a file using getline()
- Is there a standard C++ grammar?
- invalid use of non-static data member
- C: using strtol endptr is never NULL, cannot check if value is integer only?
- use of class template requires template argument list
- Why would this give a Use of uninitialised value of size 8
- C++ Error: Type Name is Not Allowed
- Is Python faster and lighter than C++?
- Case insensitive string comparison C++
- C++ Exception thrown: read access violation. this was nullptr
- error: switch quantity not an integer
- How to create a vector of class objects in C++?
- Is clrscr(); a function in C++?
- Cross compiler prefix and path in eclipse
- How to write log base(2) in c/c++
- Reading a string from file c++
- How to memset char array with null terminating character?
- Converting from Radians to Degrees
- The system cannot find the file specified. in Visual Studio
- Python for C++ Developers
- Remove last character from C++ string
- Converting String to Cstring in C++
- creating dynamic array of string c++
- Initializing default values in a struct
- Warning: comparison of distinct pointer types
- Two decimal places using printf( )
- error C2244 unable to match function definition to an existing declaration
- Initializing pointers in C++
- Static vs dynamic type checking in C++
- “No rule to make target ‘install'”… But Makefile exists
- How to determine the version of the C++ standard used by the compiler?
- Make / gcc cryptic error 2: how to have more information?
- stack around the variable…was corrupted
- Creating a list to hold objects in C++
- What does “warning: not all control paths return a value” mean? (C++)
- Array of Linked Lists C++
- Is it still safe to delete nullptr in c++0x?
- Declaration is incompatible with type
- One or more multiply defined symbols found
- I’m getting the error “stoi is not a member of std” in myprogramminglab [duplicate]
- Template constructor in a class template – how to explicitly specify template argument for the 2nd parameter?
- C++ float array initialization