File Pointer

using namespace std;

int main() {
	char data[80], ch;
	cout << "Enter a string for file:" << endl;
	cin >> data;

	/* Input output stream */
	/* Not create a file */
	fstream file;

	/* Open file in read and write mode */"data.txt", ios::in | ios::out);

	for( int i = 0; i < strlen(data); i++)

		/* Write character using put() */

	cout << "Reading from begining of the file" << endl;

	/* Move file pointer at the start */
	while(file) {

		/* Read character using get() */
		cout << ch;
	cout << endl;
	return 0;

/* Output */
Enter a text for file:

Reading from begining of the file

Comments (0)

  • To add your comment please or

We use cookies to improve your experience on our site and to show you personalised advertising. Please read our cookie policy and privacy policy.

Got It!