Answers for "how to add and read a file in c++ in visual studio"

C++
1

how to add and read a file in c++ in visual studio

#include <iostream>
#include <string>
#include <iomanip>
#include <fstream>

using namespace std;

int main() {

	string input;
	fstream file;
	char ch; 


	cout << "Please enter the file name. ";
	cin >> input;

	file.open(input, ios::in);

	if (file) {

		file.get(ch);
		
		while (file) {
			cout << ch;
			file.get(ch);
		}
		file.close();
	}
	else {

		cout << "Error! " << endl;
	}


	system("pause");
	return 0;

}
Posted by: Guest on August-30-2020

Code answers related to "how to add and read a file in c++ in visual studio"

Browse Popular Code Answers by Language