Friday, 22 January 2016

C Plus Plus Program to Create a File & Store Information --- cppexamples

Leave a Comment
Questions:

C Plus Plus Program to Create a File & Store Information

Explanation:

This tutorial will teach you how to write on a file. This requires another standard C++ library called fstream, which defines three new data types:

ofstream : This data type represents the output file stream and is used to create files and to write information to files.

Code:

#include<iostream>
#include<fstream>
using namespace std;
void main() {
       ofstream file("Temp.txt");//creating txt file
       int number1 = 12345;
       cout << "Writing data on file";
       file << "cppexamples.blogspot.com";//wring cppexamples.blogspot.con on file..
       file << endl;
       file << number1;
       /*
       you can find Temp.txt file in project folder.
       */
       file.close();

}

Output:


C-Plus-Plus-Program-to-Create-a-File-and-Store-Information-----cppexamples

Related Articles:

C Plus Plus Program to Create a File & Store Information
If You Enjoyed This, Take 5 Seconds To Share It