Jump to content

Intro To C++/Reading & Writing Files

25% developed
From Wikibooks, open books for an open world
Intro To C++
Making statement Reading & Writing Files Pointing to Data

<fstream> library and files

[edit | edit source]

The standard C++ <fstream> library provides functions for working with files and can be used by adding an #include <fstream> directive at the start of the program.The declaration is as follows:

filestream-object object-name("file-name",modes)

The ofstream object is a filestream for writing data to the file and ifstream object is for reading data from the file. The ofstream object is used like the cout function that writes to standard output and the ifstream object works like the cinfunction that reads from standard input.

#include <iostream>;
using namespace std;

int main{

 return 0;
}