
- C++ Basics
- C++ Home
- C++ Overview
- C++ Environment Setup
- C++ Basic Syntax
- C++ Comments
- C++ Data Types
- C++ Variable Types
- C++ Variable Scope
- C++ Constants/Literals
- C++ Modifier Types
- C++ Storage Classes
- C++ Operators
- C++ Loop Types
- C++ Decision Making
- C++ Functions
- C++ Numbers
- C++ Arrays
- C++ Strings
- C++ Pointers
- C++ References
- C++ Date & Time
- C++ Basic Input/Output
- C++ Data Structures
- C++ Object Oriented
- C++ Classes & Objects
- C++ Inheritance
- C++ Overloading
- C++ Polymorphism
- C++ Abstraction
- C++ Encapsulation
- C++ Interfaces
Difference between files written in binary and text mode in C++
Text mode | Binary mode |
---|---|
In text mode various character translations are performed i.e; “\r+\f” is converted into “\n” | In binary mode, such translations are not performed. |
To write in the files: ofstream ofs (“file.txt”); Or ofstream ofs; ofs.open(“file.txt”); | to write in the files: ofstream ofs(“file.txt”,ios::binary); or ofstream ofs; ofs.open(“file.txt”, ios::binary); |
To add text at the end of the file: Ofstream ofs(“file.txt”,ios::app); or ofstream ofs; ofs.open(“file.txt”, ios::app); | To add text at the end of the file: Ofstream ofs(“file.txt”,ios::app|ios::binary); or ofstream ofs; ofs.open(“file.txt”, ios::app|ios::binary); |
To read files: ifstream in (“file.txt”); or ifstream in ; in.open(“file.txt”); | To read files: ifstream in (“file.txt”, ios::binary); or ifstream in ; in.open(“file.txt”, ios::binary); |
- Related Articles
- What are the text files and binary files in C language?
- Endian order and binary files in C++
- Adding a text plus and text written from a parameter type C in ABAP
- Reading and Writing to text files in C#
- Explain write mode operation of files in C language
- Explain read mode operation of files in C language
- Explain append mode operation of files in C language
- Difference between Memory Address Mode and Register Address Mode
- Difference Between .a and .so files
- Difference between Single-mode and Multimode Fiber
- Difference between Binary Tree and Binary Search Tree
- What is the difference between mode and median?
- Recursive Search and Replace in Text Files in Linux
- Reading and Writing to text files in Python
- Reading and Writing to text files in Python Program

Advertisements