C++ file handling for beginners! The easiest way to read/write into text files!

Published: 28 April 2021
on channel: CodeBeauty
336k
9k

Learn how to solve problems and build projects with these Free E-Books ⬇️
C++ Lambdas e-book - free download here:
Entire Object-Pascal step-by-step guide - free download here:

My Practical Programming Course:
Experience the power of practical learning, gain career-ready skills, and start building real applications!
This is a step-by-step course designed to take you from beginner to expert in no time!
Here is a coupon to save 10% on your first payment (CODEBEAUTY_YT10).
Use it quickly, because it will be available for a limited time.

Download Visual Assist here:
I use it to enhance the performance, features, and support for C, C and C++ development in Visual Studio.
Download Ultra Edit here:
It is a powerful, secure text editor designed specifically for programmers.

Files are used to store data permanently.
In this video, you'll learn how to read and write into text files using C++.
In order to work with files, first, include the fstream library.
Inside this library there are three data types:
ofstream - used for writing into files
ifstream - used for reading from files
fstream - used for both read and write
In this video, I'm demonstrating the use of fstream object in file handling.

In order to open a file we use open() function.
This function receives two parameters: file name and file open mode.
The modes in which file can be opened are below:
ios::in - opens the file to read(default for ifstream)
ios::out - opens the file to write(default for ofstream)
ios::binary - opens the file in binary mode
ios::app- opens the file to append new info at the end
ios::ate - opens and moves the control to the end of the file
ios::trunc - removes the data in the existing file
ios::nocreate - opens the file only if it already exists
ios::noreplace - opens the file only if it doesn't already exist

We can also combine different modes using symbol |
For example:
myFile.open(“saldinaFile.txt”, ios::out | ios::in);
In this example, we are opening saldinaFile.txt for both writing and reading.

Create Modern Apps, 5x faster, with less code, Download FREE C++Builder Trial:

If you've found my content helpful and would like to support me, you now have the option to buy me a coffee or a cookie! It's a small gesture of gratitude that means a lot to me and helps me keep creating free educational videos for you. Use the link to make a contribution:
However, please don't feel obligated to do so. I appreciate every one of you, and I will continue to share valuable content with you regardless of whether you choose to support me in this way. Thank you for being part of the Code Beauty community! ️

Contents:
00:00 - Intro
01:02 - Write into a text file using C++
07:46 - Append to a text file using C++
10:35 - Read from a text file using C++
15:56 - Tasks to test your C++ knowledge!

Task 1. ASCII Table video:
Task 2. Structures video:

Add me on:
Instagram -
Twitter -


Watch video C++ file handling for beginners! The easiest way to read/write into text files! online without registration, duration 19 minute 09 second in high hd quality. This video was added by user CodeBeauty 28 April 2021, don't forget to share it with your friends and acquaintances, it has been viewed on our site 336 thousand once and liked it 9 thousand people.