{"id":25045,"date":"2021-02-26T16:14:00","date_gmt":"2021-02-26T10:44:00","guid":{"rendered":"https:\/\/www.mygreatlearning.com\/blog\/file-handling-in-cpp\/"},"modified":"2024-11-13T16:12:40","modified_gmt":"2024-11-13T10:42:40","slug":"file-handling-in-cpp","status":"publish","type":"post","link":"https:\/\/www.mygreatlearning.com\/blog\/file-handling-in-cpp\/","title":{"rendered":"File Handling in C++ | How to Open, Read and Close"},"content":{"rendered":"\n<h2 class=\"wp-block-heading\" id=\"what-is-file-handling-in-c\"><strong>What is File Handling in C++?<\/strong><\/h2>\n\n\n\n<p>File handling in C++ is a mechanism to store the output of a program in a file and help perform various operations on it. Files help store these data permanently on a storage device. <\/p>\n\n\n\n<p>The term \u201cData\u201d is commonly referred to as known facts or information. In the present era, data plays a vital role. It helps to describe, diagnose, predict or prescribe. But to achieve all this, we need to store it somewhere. You all would argue that there are so many text editors like \u2018Notepad\u2019 and \u2018MS Office\u2019, which help us store data in the form of text. You are right! But here we are discussing at a level of programming. In contrast, text editors like \u2018Notepad\u2019 and \u2018MS Office\u2019 are pre-built and cannot be accessed at the programming level to store data. File Handling is a hot topic when it comes to storing such programming data. <\/p>\n\n\n\n    <div class=\"courses-cta-container\">\n        <div class=\"courses-cta-card\">\n            <div class=\"courses-cta-header\">\n                <div class=\"courses-learn-icon\"><\/div>\n                <span class=\"courses-learn-text\">Academy Pro<\/span>\n            <\/div>\n            <p class=\"courses-cta-title\">\n                <a href=\"https:\/\/www.mygreatlearning.com\/academy\/premium\/learn-c-programming-for-beginners-to-advanced\" class=\"courses-cta-title-link\">C++ Programming Course<\/a>\n            <\/p>\n            <p class=\"courses-cta-description\">Master key C++ programming concepts like variables, functions, OOP, and control structures. Build real-world projects such as a banking system and grade management tool.<\/p>\n            <div class=\"courses-cta-stats\">\n                <div class=\"courses-stat-item\">\n                    <div class=\"courses-stat-icon courses-user-icon\"><\/div>\n                    <span>Beginner to Advanced Level<\/span>\n                <\/div>\n                <div class=\"courses-stat-item\">\n                    <div class=\"courses-stat-icon courses-star-icon\"><\/div>\n                    <span>8.1 hrs<\/span>\n                <\/div>\n            <\/div>\n            <a href=\"https:\/\/www.mygreatlearning.com\/academy\/premium\/learn-c-programming-for-beginners-to-advanced\" class=\"courses-cta-button\">\n                Start Free Trial\n                <div class=\"courses-arrow-icon\"><\/div>\n            <\/a>\n        <\/div>\n    <\/div>\n\n\n\n<p>Almost every programming language has a \u2018File Handling\u2019 method to deal with the storage of data. In this article, we will learn about file handling in C++. But, before that, if you are a newbie at C++, you could check out this <a rel=\"noreferrer noopener\" href=\"https:\/\/www.mygreatlearning.com\/academy\/learn-for-free\/courses\/introduction-to-c\" target=\"_blank\">free course on C++<\/a> to learn the basics. <br>Now, This topic of file handling is further divided into sub-topics:&nbsp;<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li>Create a file<\/li>\n\n\n\n<li>Open a file<\/li>\n\n\n\n<li>Read from a file<\/li>\n\n\n\n<li>Write to a file<\/li>\n\n\n\n<li>Close a file<\/li>\n<\/ul>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"fstream-library\"><strong>fstream library<\/strong><\/h2>\n\n\n\n<p>Before diving into each sub-topics, let us first learn about the header file we will be using to gain access to the file handling method. In C++, fstream library is used to handle files, and it is dealt with the help of three classes known as ofstream, ifstream and fstream.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"ofstream\"><strong>ofstream:<\/strong><\/h3>\n\n\n\n<p>This class helps create and write the data to the file obtained from the program\u2019s output. It is also known as the input stream.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"ifstream\"><strong>ifstream:<\/strong><\/h3>\n\n\n\n<p>We use this class to read data from files and also known as the input stream.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"fstream\"><strong>fstream:<\/strong> <\/h3>\n\n\n\n<p>This class is the combination of both ofstream and ifstream. It provides the capability of creating, writing and reading a file.<\/p>\n\n\n\n<p>To access the following classes, you must include the fstream as a header file like how we declare iostream in the header.<\/p>\n\n\n\n<h4 class=\"wp-block-heading\" id=\"example\"><strong>Example:<\/strong><\/h4>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: cpp; title: ; notranslate\" title=\"\">\n#include&lt;iostream&gt;\n\n#include&lt;fstream&gt;\n<\/pre><\/div>\n\n\n<p>After including the header file, there comes a question saying do we need to create the file within the program or else do we need to use an existing file. But this isn\u2019t that difficult to answer because, in C++, we get four different methods to handle files. Let's discuss them one by one. <\/p>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"file-operations-in-c\"><strong>File Operations in C++<\/strong><\/h2>\n\n\n\n<p>C++ provides us with four different operations for file handling. They are: <\/p>\n\n\n\n<ol class=\"wp-block-list\">\n<li><strong>open()<\/strong> \u2013 This is used to create a file.<\/li>\n\n\n\n<li><strong>read()&nbsp; \u2013 <\/strong>This is used to read the data from the file.<\/li>\n\n\n\n<li><strong>write() \u2013 <\/strong>This is used to write new data to file.<\/li>\n\n\n\n<li><strong>close() \u2013 <\/strong>This is used to close the file.<\/li>\n<\/ol>\n\n\n\n<p>We will look into each of these and try to understand them better. To practice file input and output concepts, try building <a href=\"https:\/\/www.mygreatlearning.com\/blog\/cpp-projects\/\">C++ projects<\/a> such as a file-based student database, a text file analyzer, or a simple log generator<\/p>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"opening-files-in-c\">Opening files in C++<\/h2>\n\n\n\n<p>To read or enter data to a file, we need to open it first. This can be performed with the help of \u2018ifstream\u2019 for reading and \u2018fstream\u2019 or \u2018ofstream\u2019 for writing or appending to the file. All these three objects have open() function pre-built in them.<\/p>\n\n\n\n<h4 class=\"wp-block-heading\" id=\"syntax\"><strong>Syntax:<\/strong><\/h4>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: cpp; title: ; notranslate\" title=\"\">\n open( FileName , Mode );\n<\/pre><\/div>\n\n\n<p>Here:<\/p>\n\n\n\n<p>FileName \u2013 It denotes the name of file which has to be opened.<\/p>\n\n\n\n<p>Mode \u2013 There different mode to open a file and it explained in this article.<\/p>\n\n\n\n<figure class=\"wp-block-table\"><table><tbody><tr><td><strong>Mode<\/strong><\/td><td><strong>Description<\/strong><\/td><\/tr><tr><td><strong>iso::in<\/strong><\/td><td>File opened in reading mode<\/td><\/tr><tr><td><strong>iso::out<\/strong><\/td><td>File opened in write mode<\/td><\/tr><tr><td><strong>iso::app<\/strong><\/td><td>File opened in append mode<\/td><\/tr><tr><td><strong>iso::ate<\/strong><\/td><td>File opened in append mode but read and write performed at the end of the file.<\/td><\/tr><tr><td><strong>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; iso::binary<\/strong><\/td><td>File opened in binary mode<\/td><\/tr><tr><td><strong>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; iso::trunc<\/strong><\/td><td>File opened in truncate mode<\/td><\/tr><tr><td><strong>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; iso::nocreate<\/strong><\/td><td>The file opens only if it exists<\/td><\/tr><tr><td><strong>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; iso::noreplace<\/strong><\/td><td>The file opens only if it doesn\u2019t exist<\/td><\/tr><\/tbody><\/table><\/figure>\n\n\n\n<p>In C++, we can use two modes simultaneously with the help of | (OR) operator.<\/p>\n\n\n\n<h4 class=\"wp-block-heading\" id=\"program-for-opening-file\"><strong>Program for Opening File<\/strong>:<\/h4>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: cpp; title: ; notranslate\" title=\"\">\n#include&lt;iostream&gt;\t\t\n#include&lt;fstream&gt;\nusing namespace std;\nint main(){\n\tfstream FileName;\t\t\t\t\n\tFileName.open(&quot;FileName&quot;, ios::out);\t\n\tif (!FileName){\t\t\t\t\t\n\t\tcout&lt;&lt;&quot;Error while creating the file&quot;;\t\n\t}\n\telse{\n\t\tcout&lt;&lt;&quot;File created successfully&quot;;\t\n\t\tFileName.close(); \t\t\t\n\t}\n\treturn 0;\n}\n\n<\/pre><\/div>\n\n\n<h4 class=\"wp-block-heading\" id=\"explanation-of-above-code\"><strong>Explanation of above code<\/strong><\/h4>\n\n\n\n<ol class=\"wp-block-list\">\n<li>Here we have an iostream library, which is responsible for input\/output stream.<\/li>\n\n\n\n<li>We also have a fstream library, which is responsible for handling files.<\/li>\n\n\n\n<li>Creating an object of the fstream class and named it as \u2018FileName\u2019.<\/li>\n\n\n\n<li>On the above-created object, we have to apply the open() function to create a new file, and the mode is set to \u2018out\u2019 which will allow us to write into the file.<\/li>\n\n\n\n<li>We use the \u2018if\u2019 statement to check for the file creation.<\/li>\n\n\n\n<li>Prints the message to console if the file doesn\u2019t exist.<\/li>\n\n\n\n<li>Prints the message to console if the file exists\/created.<\/li>\n\n\n\n<li>We use the close() function on the object to close the file.<\/li>\n<\/ol>\n\n\n\n<h4 class=\"wp-block-heading\" id=\"output\"><strong>Output<\/strong><\/h4>\n\n\n\n<p>File created successfully<\/p>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"writing-to-file\"><strong>Writing to File<\/strong><\/h2>\n\n\n\n<p>Till now, we learned how to create the file using C++. Now, we will learn how to write data to file which we created before. We will use fstream or ofstream object to write data into the file and to do so; we will use stream insertion operator (&lt;&lt;) along with the text enclosed within the double-quotes.<\/p>\n\n\n\n<p>With the help of open() function, we will create a new file named \u2018FileName\u2019 and then we will set the mode to \u2018ios::out\u2019 as we have to write the data to file.<\/p>\n\n\n\n<h4 class=\"wp-block-heading\" id=\"syntax\"><strong>Syntax:<\/strong><\/h4>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: cpp; title: ; notranslate\" title=\"\">\n FileName&lt;&lt;&quot;Insert the text here&quot;;\n<\/pre><\/div>\n\n\n<h4 class=\"wp-block-heading\" id=\"program-for-writing-to-file\"><strong>Program for Writing to File<\/strong>:<\/h4>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: cpp; title: ; notranslate\" title=\"\">\n#include&lt;iostream&gt;                         \n#include&lt;fstream&gt;                            \nusing namespace std;\nint main() {\n    fstream FileName;                       \n    FileName.open(&quot;FileName.txt&quot;, ios::out);                \n    if (!FileName) {                            \n        cout&lt;&lt;&quot; Error while creating the file &quot;;          \n    }\n    else {\n        cout&lt;&lt;&quot;File created and data got written to file&quot;;    \n        FileName&lt;&lt;&quot;This is a blog posted on Great Learning&quot;;  \n        FileName.close();                   \n    }\n    return 0;\n}\n<\/pre><\/div>\n\n\n<h4 class=\"wp-block-heading\" id=\"explanation-of-above-code\"><strong>Explanation of above code<\/strong><\/h4>\n\n\n\n<ol class=\"wp-block-list\">\n<li>Here we have an iostream library, which is responsible for input\/output stream.<\/li>\n\n\n\n<li>We also have a fstream library, which is responsible for handling files.<\/li>\n\n\n\n<li>Creating an object of the fstream class and named it as \u2018FileName\u2019.<\/li>\n\n\n\n<li>On the above-created object, we have to apply the open() function to create a new file, and the mode is set to \u2018out\u2019 which will allow us to write into the file.<\/li>\n\n\n\n<li>We use the \u2018if\u2019 statement to check for the file creation.<\/li>\n\n\n\n<li>Prints the message to console if the file doesn\u2019t exist.<\/li>\n\n\n\n<li>Prints the message to console if the file exists\/created.<\/li>\n\n\n\n<li>Writing the data to the created file.<\/li>\n\n\n\n<li>We use the close() function on the object to close the file.<\/li>\n<\/ol>\n\n\n\n<h4 class=\"wp-block-heading\" id=\"output\"><strong>Output<\/strong><\/h4>\n\n\n\n<p>File created and data got written to file<\/p>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"reading-from-file-in-c\"><strong>Reading from file<\/strong> in C++<\/h2>\n\n\n\n<p>Getting the data from the file is an essential thing to perform because without getting the data, we cannot perform any task. But don\u2019t worry, C++ provides that option too. We can perform the reading of data from a file with the CIN to get data from the user, but then we use CIN to take inputs from the user\u2019s standard console. Here we will use fstream or ifstream.<\/p>\n\n\n\n<h4 class=\"wp-block-heading\" id=\"syntax\"><strong>Syntax:<\/strong><\/h4>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: cpp; title: ; notranslate\" title=\"\">\n FileName&gt;&gt;Variable;\n<\/pre><\/div>\n\n\n<h4 class=\"wp-block-heading\" id=\"content-of-filename-txt\"><strong>Content of FileName.txt:<\/strong><\/h4>\n\n\n\n<p><strong><\/strong>Hello World, Thank You for Visiting Great Learning.<\/p>\n\n\n\n<h4 class=\"wp-block-heading\" id=\"program-for-reading-from-file\"><strong>Program for Reading from File:<\/strong><\/h4>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: cpp; title: ; notranslate\" title=\"\">\n#include&lt;iostream&gt;\t\t\t\t\t\t\n#include &lt;fstream&gt;\t\t\t\t\t\t\nusing namespace std;\nint main() {\n\tfstream FileName;\t\t\t\t\t\n\tFileName.open(&quot;FileName.txt&quot;, ios::in);\t\t\t\n\tif (!FileName) {\t\t\t\t\t\t\n\t\tcout&lt;&lt;&quot;File doesn\u2019t exist.&quot;;\t\t\t\n\t}\n\telse {\n\t\tchar x;\t\t\t\t\t\t\n\t\twhile (1) {\t\t\t\n\t\t\tFileName&gt;&gt;x;\t\t\t\t\n\t\t\tif(FileName.eof())\t\t\t\n\t\t\t\tbreak;\t\t\t\t\n\t\t\tcout&lt;&lt;x;\t\t\t\t\t\n\t\t}\n\t}\n\tFileName.close();\t\t\t\t\t\n\treturn 0;\n}\n<\/pre><\/div>\n\n\n<h4 class=\"wp-block-heading\" id=\"explanation-of-above-code\"><strong>Explanation of above code<\/strong><\/h4>\n\n\n\n<ol class=\"wp-block-list\">\n<li>Here we have an iostream library, which is responsible for input\/output stream.<\/li>\n\n\n\n<li>We also have a fstream library which is responsible for handling files.<\/li>\n\n\n\n<li>Creating an object of the fstream class and named it \u2018FileName\u2019.<\/li>\n\n\n\n<li>On the above-created object, we have to apply the open() function to create a new file, and the mode is set to \u2018in\u2019 which will allow us to read from the file.<\/li>\n\n\n\n<li>We use the \u2018if\u2019 statement to check for the file creation.<\/li>\n\n\n\n<li>Prints the message to console if the file doesn\u2019t exist.<\/li>\n\n\n\n<li>Creating a character(char) variable with the named x.<\/li>\n\n\n\n<li>Iterating of the file with the help of while loop.<\/li>\n\n\n\n<li>Getting the file data to the variable x.<\/li>\n\n\n\n<li>Here we are using if condition with eof() which stands for the end of the file to tell the compiler to read till the file\u2019s end.<\/li>\n\n\n\n<li>We use the 'break' statement to stop the reading from file when it reaches the end.<\/li>\n\n\n\n<li>The print statement to print the content that is available in the variable x.<\/li>\n\n\n\n<li>We use the close() function on the object to close the file<\/li>\n<\/ol>\n\n\n\n<h4 class=\"wp-block-heading\" id=\"output\"><strong>Output<\/strong><\/h4>\n\n\n\n<p>Hello World, Thank You for Visiting Great Learning.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"infile-c\"><strong>Infile C++<\/strong><\/h3>\n\n\n\n<p>We can also use inFile to read from the file. Here, <code>inFile &gt;&gt; S<\/code>&nbsp;takes in the file stream, which is your file data, and uses a space delimiter (breaks it up by whitespace) and then puts the contents in the variable S.<\/p>\n\n\n\n<p><strong>Example:<\/strong><\/p>\n\n\n\n<p>If we had a file that had the data:<\/p>\n\n\n\n<p>\"My Cat is Hungry\"<\/p>\n\n\n\n<p>and we used inFile &gt;&gt; S here, i.e.:<\/p>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: cpp; title: ; notranslate\" title=\"\">\nifstream inFile(&quot;file.txt&quot;)\nstring words;\nwhile(inFile &gt;&gt; words) {\n   cout &lt;&lt; words &lt;&lt; endl;\n}\n<\/pre><\/div>\n\n\n<p><strong>We will get the output:<\/strong> <\/p>\n\n\n\n<p>My<\/p>\n\n\n\n<p>Cat<\/p>\n\n\n\n<p>is<\/p>\n\n\n\n<p>Hungry<\/p>\n\n\n\n<p>The&nbsp;<code>inFile &gt;&gt; <\/code>words&nbsp;will continue to return 'true' until there are no more items separated by whitespace.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"closing-a-file-in-c\"><strong>Closing a file<\/strong> in C++<\/h2>\n\n\n\n<p>Closing a file is a good practice, and it is must to close the file. Whenever the C++ program comes to an end, it clears the allocated memory, and it closes the file. We can perform the task with the help of close() function.<\/p>\n\n\n\n<h4 class=\"wp-block-heading\" id=\"syntax\"><strong>Syntax:<\/strong><\/h4>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: cpp; title: ; notranslate\" title=\"\">\n FileName.close();\n<\/pre><\/div>\n\n\n<h4 class=\"wp-block-heading\" id=\"program-to-close-a-file\"><strong>Program to Close a File<\/strong>:<\/h4>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: cpp; title: ; notranslate\" title=\"\">\n#include &lt;iostream&gt;\t\t\t\t\t\t\n#include &lt;fstream&gt;\t\t\t\t\t\t\nusing namespace std;\nint main() {\n\tfstream FileName;\t\t\t\t\t\n\tFileName.open(&quot;FileName.txt&quot;, ios::in);\t\t\t\n\tif (!FileName) {\t\t\t\t\t\t\n\t\tcout&lt;&lt;&quot;File doesn\u2019t exist&quot;;\t\t\t\n\t}\n\telse {\n\t\tcout&lt;&lt;&quot;File opened successfully&quot;;\t\t\t\n\t\t}\n\t}\n\tFileName.close();\t\t\t\t\t\n\treturn 0;\n}\n<\/pre><\/div>\n\n\n<h4 class=\"wp-block-heading\" id=\"explanation-of-above-code\"><strong>Explanation of above code<\/strong><\/h4>\n\n\n\n<ol class=\"wp-block-list\">\n<li>Here we have an iostream library, which is responsible for input\/output stream.<\/li>\n\n\n\n<li>We also have a fstream library, which is responsible for handling files.<\/li>\n\n\n\n<li>Creating an object of the fstream class and named it as \u2018FileName\u2019.<\/li>\n\n\n\n<li>On the above-created object, we will apply the open() function to create a new file, and the mode is set to \u2018out\u2019 which allows us to write into the file.<\/li>\n\n\n\n<li>We use the \u2018if\u2019 statement to check for the file creation.<\/li>\n\n\n\n<li>Prints the message to console if the file doesn\u2019t exist.<\/li>\n\n\n\n<li>Prints the message to console if the file opened or not.&nbsp;<\/li>\n\n\n\n<li>We use the close() function on the object to close the file.<\/li>\n<\/ol>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"file-position-pointers\"><strong>File Position Pointers<\/strong><\/h2>\n\n\n\n<p>We can reposition the file-position pointer in istream and ostream using its special member functions. These member functions are 'seekg' and 'seekp'. 'seekg' or 'seek get' is used for istream and 'seekp' or 'seek put' is used for ostream. <\/p>\n\n\n\n<p>Both these member functions take long integer as arguments. A second argument is used to specify the direction of seek. The seek directions can be ios::beg( for positioning in the beginning of a stream), ios::cur( for positioning relative to a current position of a stream) and ios::end( to position relative to the end of a stream).<\/p>\n\n\n\n<p>This brings us to the end of the blog on the concept of File Handling in C++. We hope that you found this comprehensive and helpful and were able to gain the required knowledge. If you're interested in expanding your skills beyond C++, you can explore a variety of <strong><a href=\"https:\/\/www.mygreatlearning.com\/academy\">free courses with certificates<\/a><\/strong> to broaden your knowledge and earn certifications.<\/p>\n\n\n\n<p>Also, if you are preparing for Interviews, check out these&nbsp;<a rel=\"noreferrer noopener\" href=\"https:\/\/www.mygreatlearning.com\/blog\/cpp-interview-questions\/\" target=\"_blank\">Interview Questions for C++<\/a>&nbsp;to ace it like a pro.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>What is File Handling in C++? File handling in C++ is a mechanism to store the output of a program in a file and help perform various operations on it. Files help store these data permanently on a storage device. The term \u201cData\u201d is commonly referred to as known facts or information. In the present [&hellip;]<\/p>\n","protected":false},"author":41,"featured_media":25285,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_acf_changed":false,"_uag_custom_page_level_css":"","site-sidebar-layout":"default","site-content-layout":"","ast-site-content-layout":"default","site-content-style":"default","site-sidebar-style":"default","ast-global-header-display":"","ast-banner-title-visibility":"","ast-main-header-display":"","ast-hfb-above-header-display":"","ast-hfb-below-header-display":"","ast-hfb-mobile-header-display":"","site-post-title":"","ast-breadcrumbs-content":"","ast-featured-img":"","footer-sml-layout":"","ast-disable-related-posts":"","theme-transparent-header-meta":"","adv-header-id-meta":"","stick-header-meta":"","header-above-stick-meta":"","header-main-stick-meta":"","header-below-stick-meta":"","astra-migrate-meta-layouts":"set","ast-page-background-enabled":"default","ast-page-background-meta":{"desktop":{"background-color":"var(--ast-global-color-4)","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""},"tablet":{"background-color":"","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""},"mobile":{"background-color":"","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""}},"ast-content-background-meta":{"desktop":{"background-color":"var(--ast-global-color-5)","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""},"tablet":{"background-color":"var(--ast-global-color-5)","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""},"mobile":{"background-color":"var(--ast-global-color-5)","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""}},"footnotes":""},"categories":[25860],"tags":[36801],"content_type":[],"class_list":["post-25045","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-software","tag-c-programming"],"acf":[],"yoast_head":"<!-- This site is optimized with the Yoast SEO Premium plugin v27.3 (Yoast SEO v27.3) - https:\/\/yoast.com\/product\/yoast-seo-premium-wordpress\/ -->\n<title>File Handling Through C++ | How to Open, Save, Read and Close<\/title>\n<meta name=\"description\" content=\"File Handling Through C++: Almost every programming language has a \u2018File Handling\u2019 method to deal with the storage of data. In this article, we will learn about file handling in C++.\" \/>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/www.mygreatlearning.com\/blog\/file-handling-in-cpp\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"File Handling in C++ | How to Open, Read and Close\" \/>\n<meta property=\"og:description\" content=\"File Handling Through C++: Almost every programming language has a \u2018File Handling\u2019 method to deal with the storage of data. In this article, we will learn about file handling in C++.\" \/>\n<meta property=\"og:url\" content=\"https:\/\/www.mygreatlearning.com\/blog\/file-handling-in-cpp\/\" \/>\n<meta property=\"og:site_name\" content=\"Great Learning Blog: Free Resources what Matters to shape your Career!\" \/>\n<meta property=\"article:publisher\" content=\"https:\/\/www.facebook.com\/GreatLearningOfficial\/\" \/>\n<meta property=\"article:published_time\" content=\"2021-02-26T10:44:00+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2024-11-13T10:42:40+00:00\" \/>\n<meta property=\"og:image\" content=\"http:\/\/www.mygreatlearning.com\/blog\/wp-content\/uploads\/2021\/02\/iStock-1147195672.jpg\" \/>\n\t<meta property=\"og:image:width\" content=\"1253\" \/>\n\t<meta property=\"og:image:height\" content=\"836\" \/>\n\t<meta property=\"og:image:type\" content=\"image\/jpeg\" \/>\n<meta name=\"author\" content=\"Great Learning Editorial Team\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:creator\" content=\"@https:\/\/twitter.com\/Great_Learning\" \/>\n<meta name=\"twitter:site\" content=\"@Great_Learning\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"Great Learning Editorial Team\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"8 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\\\/\\\/schema.org\",\"@graph\":[{\"@type\":\"Article\",\"@id\":\"https:\\\/\\\/www.mygreatlearning.com\\\/blog\\\/file-handling-in-cpp\\\/#article\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/www.mygreatlearning.com\\\/blog\\\/file-handling-in-cpp\\\/\"},\"author\":{\"name\":\"Great Learning Editorial Team\",\"@id\":\"https:\\\/\\\/www.mygreatlearning.com\\\/blog\\\/#\\\/schema\\\/person\\\/6f993d1be4c584a335951e836f2656ad\"},\"headline\":\"File Handling in C++ | How to Open, Read and Close\",\"datePublished\":\"2021-02-26T10:44:00+00:00\",\"dateModified\":\"2024-11-13T10:42:40+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\\\/\\\/www.mygreatlearning.com\\\/blog\\\/file-handling-in-cpp\\\/\"},\"wordCount\":1857,\"commentCount\":0,\"publisher\":{\"@id\":\"https:\\\/\\\/www.mygreatlearning.com\\\/blog\\\/#organization\"},\"image\":{\"@id\":\"https:\\\/\\\/www.mygreatlearning.com\\\/blog\\\/file-handling-in-cpp\\\/#primaryimage\"},\"thumbnailUrl\":\"https:\\\/\\\/www.mygreatlearning.com\\\/blog\\\/wp-content\\\/uploads\\\/2021\\\/02\\\/iStock-1147195672.jpg\",\"keywords\":[\"C++ Programming\"],\"articleSection\":[\"IT\\\/Software Development\"],\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"CommentAction\",\"name\":\"Comment\",\"target\":[\"https:\\\/\\\/www.mygreatlearning.com\\\/blog\\\/file-handling-in-cpp\\\/#respond\"]}]},{\"@type\":\"WebPage\",\"@id\":\"https:\\\/\\\/www.mygreatlearning.com\\\/blog\\\/file-handling-in-cpp\\\/\",\"url\":\"https:\\\/\\\/www.mygreatlearning.com\\\/blog\\\/file-handling-in-cpp\\\/\",\"name\":\"File Handling Through C++ | How to Open, Save, Read and Close\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/www.mygreatlearning.com\\\/blog\\\/#website\"},\"primaryImageOfPage\":{\"@id\":\"https:\\\/\\\/www.mygreatlearning.com\\\/blog\\\/file-handling-in-cpp\\\/#primaryimage\"},\"image\":{\"@id\":\"https:\\\/\\\/www.mygreatlearning.com\\\/blog\\\/file-handling-in-cpp\\\/#primaryimage\"},\"thumbnailUrl\":\"https:\\\/\\\/www.mygreatlearning.com\\\/blog\\\/wp-content\\\/uploads\\\/2021\\\/02\\\/iStock-1147195672.jpg\",\"datePublished\":\"2021-02-26T10:44:00+00:00\",\"dateModified\":\"2024-11-13T10:42:40+00:00\",\"description\":\"File Handling Through C++: Almost every programming language has a \u2018File Handling\u2019 method to deal with the storage of data. In this article, we will learn about file handling in C++.\",\"breadcrumb\":{\"@id\":\"https:\\\/\\\/www.mygreatlearning.com\\\/blog\\\/file-handling-in-cpp\\\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\\\/\\\/www.mygreatlearning.com\\\/blog\\\/file-handling-in-cpp\\\/\"]}]},{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\\\/\\\/www.mygreatlearning.com\\\/blog\\\/file-handling-in-cpp\\\/#primaryimage\",\"url\":\"https:\\\/\\\/www.mygreatlearning.com\\\/blog\\\/wp-content\\\/uploads\\\/2021\\\/02\\\/iStock-1147195672.jpg\",\"contentUrl\":\"https:\\\/\\\/www.mygreatlearning.com\\\/blog\\\/wp-content\\\/uploads\\\/2021\\\/02\\\/iStock-1147195672.jpg\",\"width\":1253,\"height\":836,\"caption\":\"Focused young developer coding late in office writing script shown on computer monitors, serious handsome coder programmer hacker programming developing software applications working alone at night\"},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\\\/\\\/www.mygreatlearning.com\\\/blog\\\/file-handling-in-cpp\\\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Blog\",\"item\":\"https:\\\/\\\/www.mygreatlearning.com\\\/blog\\\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"IT\\\/Software Development\",\"item\":\"https:\\\/\\\/www.mygreatlearning.com\\\/blog\\\/software\\\/\"},{\"@type\":\"ListItem\",\"position\":3,\"name\":\"File Handling in C++ | How to Open, Read and Close\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\\\/\\\/www.mygreatlearning.com\\\/blog\\\/#website\",\"url\":\"https:\\\/\\\/www.mygreatlearning.com\\\/blog\\\/\",\"name\":\"Great Learning Blog\",\"description\":\"Learn, Upskill &amp; Career Development Guide and Resources\",\"publisher\":{\"@id\":\"https:\\\/\\\/www.mygreatlearning.com\\\/blog\\\/#organization\"},\"alternateName\":\"Great Learning\",\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\\\/\\\/www.mygreatlearning.com\\\/blog\\\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"en-US\"},{\"@type\":\"Organization\",\"@id\":\"https:\\\/\\\/www.mygreatlearning.com\\\/blog\\\/#organization\",\"name\":\"Great Learning\",\"url\":\"https:\\\/\\\/www.mygreatlearning.com\\\/blog\\\/\",\"logo\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\\\/\\\/www.mygreatlearning.com\\\/blog\\\/#\\\/schema\\\/logo\\\/image\\\/\",\"url\":\"https:\\\/\\\/www.mygreatlearning.com\\\/blog\\\/wp-content\\\/uploads\\\/2022\\\/06\\\/GL-Logo.jpg\",\"contentUrl\":\"https:\\\/\\\/www.mygreatlearning.com\\\/blog\\\/wp-content\\\/uploads\\\/2022\\\/06\\\/GL-Logo.jpg\",\"width\":900,\"height\":900,\"caption\":\"Great Learning\"},\"image\":{\"@id\":\"https:\\\/\\\/www.mygreatlearning.com\\\/blog\\\/#\\\/schema\\\/logo\\\/image\\\/\"},\"sameAs\":[\"https:\\\/\\\/www.facebook.com\\\/GreatLearningOfficial\\\/\",\"https:\\\/\\\/x.com\\\/Great_Learning\",\"https:\\\/\\\/www.instagram.com\\\/greatlearningofficial\\\/\",\"https:\\\/\\\/www.linkedin.com\\\/school\\\/great-learning\\\/\",\"https:\\\/\\\/in.pinterest.com\\\/greatlearning12\\\/\",\"https:\\\/\\\/www.youtube.com\\\/user\\\/beaconelearning\\\/\"],\"description\":\"Great Learning is a leading global ed-tech company for professional training and higher education. It offers comprehensive, industry-relevant, hands-on learning programs across various business, technology, and interdisciplinary domains driving the digital economy. These programs are developed and offered in collaboration with the world's foremost academic institutions.\",\"email\":\"info@mygreatlearning.com\",\"legalName\":\"Great Learning Education Services Pvt. Ltd\",\"foundingDate\":\"2013-11-29\",\"numberOfEmployees\":{\"@type\":\"QuantitativeValue\",\"minValue\":\"1001\",\"maxValue\":\"5000\"}},{\"@type\":\"Person\",\"@id\":\"https:\\\/\\\/www.mygreatlearning.com\\\/blog\\\/#\\\/schema\\\/person\\\/6f993d1be4c584a335951e836f2656ad\",\"name\":\"Great Learning Editorial Team\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\\\/\\\/www.mygreatlearning.com\\\/blog\\\/wp-content\\\/uploads\\\/2022\\\/02\\\/unnamed.webp\",\"url\":\"https:\\\/\\\/www.mygreatlearning.com\\\/blog\\\/wp-content\\\/uploads\\\/2022\\\/02\\\/unnamed.webp\",\"contentUrl\":\"https:\\\/\\\/www.mygreatlearning.com\\\/blog\\\/wp-content\\\/uploads\\\/2022\\\/02\\\/unnamed.webp\",\"caption\":\"Great Learning Editorial Team\"},\"description\":\"The Great Learning Editorial Staff includes a dynamic team of subject matter experts, instructors, and education professionals who combine their deep industry knowledge with innovative teaching methods. Their mission is to provide learners with the skills and insights needed to excel in their careers, whether through upskilling, reskilling, or transitioning into new fields.\",\"sameAs\":[\"https:\\\/\\\/www.mygreatlearning.com\\\/\",\"https:\\\/\\\/in.linkedin.com\\\/school\\\/great-learning\\\/\",\"https:\\\/\\\/x.com\\\/https:\\\/\\\/twitter.com\\\/Great_Learning\",\"https:\\\/\\\/www.youtube.com\\\/channel\\\/UCObs0kLIrDjX2LLSybqNaEA\"],\"award\":[\"Best EdTech Company of the Year 2024\",\"Education Economictimes Outstanding Education\\\/Edtech Solution Provider of the Year 2024\",\"Leading E-learning Platform 2024\"],\"url\":\"https:\\\/\\\/www.mygreatlearning.com\\\/blog\\\/author\\\/greatlearning\\\/\"}]}<\/script>\n<!-- \/ Yoast SEO Premium plugin. -->","yoast_head_json":{"title":"File Handling Through C++ | How to Open, Save, Read and Close","description":"File Handling Through C++: Almost every programming language has a \u2018File Handling\u2019 method to deal with the storage of data. In this article, we will learn about file handling in C++.","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/www.mygreatlearning.com\/blog\/file-handling-in-cpp\/","og_locale":"en_US","og_type":"article","og_title":"File Handling in C++ | How to Open, Read and Close","og_description":"File Handling Through C++: Almost every programming language has a \u2018File Handling\u2019 method to deal with the storage of data. In this article, we will learn about file handling in C++.","og_url":"https:\/\/www.mygreatlearning.com\/blog\/file-handling-in-cpp\/","og_site_name":"Great Learning Blog: Free Resources what Matters to shape your Career!","article_publisher":"https:\/\/www.facebook.com\/GreatLearningOfficial\/","article_published_time":"2021-02-26T10:44:00+00:00","article_modified_time":"2024-11-13T10:42:40+00:00","og_image":[{"width":1253,"height":836,"url":"http:\/\/www.mygreatlearning.com\/blog\/wp-content\/uploads\/2021\/02\/iStock-1147195672.jpg","type":"image\/jpeg"}],"author":"Great Learning Editorial Team","twitter_card":"summary_large_image","twitter_creator":"@https:\/\/twitter.com\/Great_Learning","twitter_site":"@Great_Learning","twitter_misc":{"Written by":"Great Learning Editorial Team","Est. reading time":"8 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/www.mygreatlearning.com\/blog\/file-handling-in-cpp\/#article","isPartOf":{"@id":"https:\/\/www.mygreatlearning.com\/blog\/file-handling-in-cpp\/"},"author":{"name":"Great Learning Editorial Team","@id":"https:\/\/www.mygreatlearning.com\/blog\/#\/schema\/person\/6f993d1be4c584a335951e836f2656ad"},"headline":"File Handling in C++ | How to Open, Read and Close","datePublished":"2021-02-26T10:44:00+00:00","dateModified":"2024-11-13T10:42:40+00:00","mainEntityOfPage":{"@id":"https:\/\/www.mygreatlearning.com\/blog\/file-handling-in-cpp\/"},"wordCount":1857,"commentCount":0,"publisher":{"@id":"https:\/\/www.mygreatlearning.com\/blog\/#organization"},"image":{"@id":"https:\/\/www.mygreatlearning.com\/blog\/file-handling-in-cpp\/#primaryimage"},"thumbnailUrl":"https:\/\/www.mygreatlearning.com\/blog\/wp-content\/uploads\/2021\/02\/iStock-1147195672.jpg","keywords":["C++ Programming"],"articleSection":["IT\/Software Development"],"inLanguage":"en-US","potentialAction":[{"@type":"CommentAction","name":"Comment","target":["https:\/\/www.mygreatlearning.com\/blog\/file-handling-in-cpp\/#respond"]}]},{"@type":"WebPage","@id":"https:\/\/www.mygreatlearning.com\/blog\/file-handling-in-cpp\/","url":"https:\/\/www.mygreatlearning.com\/blog\/file-handling-in-cpp\/","name":"File Handling Through C++ | How to Open, Save, Read and Close","isPartOf":{"@id":"https:\/\/www.mygreatlearning.com\/blog\/#website"},"primaryImageOfPage":{"@id":"https:\/\/www.mygreatlearning.com\/blog\/file-handling-in-cpp\/#primaryimage"},"image":{"@id":"https:\/\/www.mygreatlearning.com\/blog\/file-handling-in-cpp\/#primaryimage"},"thumbnailUrl":"https:\/\/www.mygreatlearning.com\/blog\/wp-content\/uploads\/2021\/02\/iStock-1147195672.jpg","datePublished":"2021-02-26T10:44:00+00:00","dateModified":"2024-11-13T10:42:40+00:00","description":"File Handling Through C++: Almost every programming language has a \u2018File Handling\u2019 method to deal with the storage of data. In this article, we will learn about file handling in C++.","breadcrumb":{"@id":"https:\/\/www.mygreatlearning.com\/blog\/file-handling-in-cpp\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/www.mygreatlearning.com\/blog\/file-handling-in-cpp\/"]}]},{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/www.mygreatlearning.com\/blog\/file-handling-in-cpp\/#primaryimage","url":"https:\/\/www.mygreatlearning.com\/blog\/wp-content\/uploads\/2021\/02\/iStock-1147195672.jpg","contentUrl":"https:\/\/www.mygreatlearning.com\/blog\/wp-content\/uploads\/2021\/02\/iStock-1147195672.jpg","width":1253,"height":836,"caption":"Focused young developer coding late in office writing script shown on computer monitors, serious handsome coder programmer hacker programming developing software applications working alone at night"},{"@type":"BreadcrumbList","@id":"https:\/\/www.mygreatlearning.com\/blog\/file-handling-in-cpp\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Blog","item":"https:\/\/www.mygreatlearning.com\/blog\/"},{"@type":"ListItem","position":2,"name":"IT\/Software Development","item":"https:\/\/www.mygreatlearning.com\/blog\/software\/"},{"@type":"ListItem","position":3,"name":"File Handling in C++ | How to Open, Read and Close"}]},{"@type":"WebSite","@id":"https:\/\/www.mygreatlearning.com\/blog\/#website","url":"https:\/\/www.mygreatlearning.com\/blog\/","name":"Great Learning Blog","description":"Learn, Upskill &amp; Career Development Guide and Resources","publisher":{"@id":"https:\/\/www.mygreatlearning.com\/blog\/#organization"},"alternateName":"Great Learning","potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/www.mygreatlearning.com\/blog\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"},{"@type":"Organization","@id":"https:\/\/www.mygreatlearning.com\/blog\/#organization","name":"Great Learning","url":"https:\/\/www.mygreatlearning.com\/blog\/","logo":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/www.mygreatlearning.com\/blog\/#\/schema\/logo\/image\/","url":"https:\/\/www.mygreatlearning.com\/blog\/wp-content\/uploads\/2022\/06\/GL-Logo.jpg","contentUrl":"https:\/\/www.mygreatlearning.com\/blog\/wp-content\/uploads\/2022\/06\/GL-Logo.jpg","width":900,"height":900,"caption":"Great Learning"},"image":{"@id":"https:\/\/www.mygreatlearning.com\/blog\/#\/schema\/logo\/image\/"},"sameAs":["https:\/\/www.facebook.com\/GreatLearningOfficial\/","https:\/\/x.com\/Great_Learning","https:\/\/www.instagram.com\/greatlearningofficial\/","https:\/\/www.linkedin.com\/school\/great-learning\/","https:\/\/in.pinterest.com\/greatlearning12\/","https:\/\/www.youtube.com\/user\/beaconelearning\/"],"description":"Great Learning is a leading global ed-tech company for professional training and higher education. It offers comprehensive, industry-relevant, hands-on learning programs across various business, technology, and interdisciplinary domains driving the digital economy. These programs are developed and offered in collaboration with the world's foremost academic institutions.","email":"info@mygreatlearning.com","legalName":"Great Learning Education Services Pvt. Ltd","foundingDate":"2013-11-29","numberOfEmployees":{"@type":"QuantitativeValue","minValue":"1001","maxValue":"5000"}},{"@type":"Person","@id":"https:\/\/www.mygreatlearning.com\/blog\/#\/schema\/person\/6f993d1be4c584a335951e836f2656ad","name":"Great Learning Editorial Team","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/www.mygreatlearning.com\/blog\/wp-content\/uploads\/2022\/02\/unnamed.webp","url":"https:\/\/www.mygreatlearning.com\/blog\/wp-content\/uploads\/2022\/02\/unnamed.webp","contentUrl":"https:\/\/www.mygreatlearning.com\/blog\/wp-content\/uploads\/2022\/02\/unnamed.webp","caption":"Great Learning Editorial Team"},"description":"The Great Learning Editorial Staff includes a dynamic team of subject matter experts, instructors, and education professionals who combine their deep industry knowledge with innovative teaching methods. Their mission is to provide learners with the skills and insights needed to excel in their careers, whether through upskilling, reskilling, or transitioning into new fields.","sameAs":["https:\/\/www.mygreatlearning.com\/","https:\/\/in.linkedin.com\/school\/great-learning\/","https:\/\/x.com\/https:\/\/twitter.com\/Great_Learning","https:\/\/www.youtube.com\/channel\/UCObs0kLIrDjX2LLSybqNaEA"],"award":["Best EdTech Company of the Year 2024","Education Economictimes Outstanding Education\/Edtech Solution Provider of the Year 2024","Leading E-learning Platform 2024"],"url":"https:\/\/www.mygreatlearning.com\/blog\/author\/greatlearning\/"}]}},"uagb_featured_image_src":{"full":["https:\/\/www.mygreatlearning.com\/blog\/wp-content\/uploads\/2021\/02\/iStock-1147195672.jpg",1253,836,false],"thumbnail":["https:\/\/www.mygreatlearning.com\/blog\/wp-content\/uploads\/2021\/02\/iStock-1147195672-150x150.jpg",150,150,true],"medium":["https:\/\/www.mygreatlearning.com\/blog\/wp-content\/uploads\/2021\/02\/iStock-1147195672-300x200.jpg",300,200,true],"medium_large":["https:\/\/www.mygreatlearning.com\/blog\/wp-content\/uploads\/2021\/02\/iStock-1147195672-768x512.jpg",768,512,true],"large":["https:\/\/www.mygreatlearning.com\/blog\/wp-content\/uploads\/2021\/02\/iStock-1147195672-1024x683.jpg",1024,683,true],"1536x1536":["https:\/\/www.mygreatlearning.com\/blog\/wp-content\/uploads\/2021\/02\/iStock-1147195672.jpg",1253,836,false],"2048x2048":["https:\/\/www.mygreatlearning.com\/blog\/wp-content\/uploads\/2021\/02\/iStock-1147195672.jpg",1253,836,false],"web-stories-poster-portrait":["https:\/\/www.mygreatlearning.com\/blog\/wp-content\/uploads\/2021\/02\/iStock-1147195672.jpg",640,427,false],"web-stories-publisher-logo":["https:\/\/www.mygreatlearning.com\/blog\/wp-content\/uploads\/2021\/02\/iStock-1147195672.jpg",96,64,false],"web-stories-thumbnail":["https:\/\/www.mygreatlearning.com\/blog\/wp-content\/uploads\/2021\/02\/iStock-1147195672.jpg",150,100,false]},"uagb_author_info":{"display_name":"Great Learning Editorial Team","author_link":"https:\/\/www.mygreatlearning.com\/blog\/author\/greatlearning\/"},"uagb_comment_info":1,"uagb_excerpt":"What is File Handling in C++? File handling in C++ is a mechanism to store the output of a program in a file and help perform various operations on it. Files help store these data permanently on a storage device. The term \u201cData\u201d is commonly referred to as known facts or information. In the present&hellip;","_links":{"self":[{"href":"https:\/\/www.mygreatlearning.com\/blog\/wp-json\/wp\/v2\/posts\/25045","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.mygreatlearning.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.mygreatlearning.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.mygreatlearning.com\/blog\/wp-json\/wp\/v2\/users\/41"}],"replies":[{"embeddable":true,"href":"https:\/\/www.mygreatlearning.com\/blog\/wp-json\/wp\/v2\/comments?post=25045"}],"version-history":[{"count":36,"href":"https:\/\/www.mygreatlearning.com\/blog\/wp-json\/wp\/v2\/posts\/25045\/revisions"}],"predecessor-version":[{"id":111501,"href":"https:\/\/www.mygreatlearning.com\/blog\/wp-json\/wp\/v2\/posts\/25045\/revisions\/111501"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.mygreatlearning.com\/blog\/wp-json\/wp\/v2\/media\/25285"}],"wp:attachment":[{"href":"https:\/\/www.mygreatlearning.com\/blog\/wp-json\/wp\/v2\/media?parent=25045"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.mygreatlearning.com\/blog\/wp-json\/wp\/v2\/categories?post=25045"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.mygreatlearning.com\/blog\/wp-json\/wp\/v2\/tags?post=25045"},{"taxonomy":"content_type","embeddable":true,"href":"https:\/\/www.mygreatlearning.com\/blog\/wp-json\/wp\/v2\/content_type?post=25045"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}