Opening Text Files

Hey guys, In this program so far a user can input text they want on a text file. Two main issues with this:

1. When a user makes a file name i need it to automatically be turned into a .txt without them having to type it.

2. The main part is after the user has made a file, they can open view it when it's built.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
#include <fstream>
#include <iostream>
#include <string>
using namespace std;

int main()
{
	ofstream f;
	string filename;
	string fg;

	
	
	cout << "What is fg: ";
	getline(cin, fg);
	cout << "Please enter a file name to write: ";
	getline(cin, filename);
	f.open(filename.c_str());
	f << fg;
	f.close();

	return 0;
}
Add .txt to the filename.
Topic archived. No new replies allowed.