Letting User Choose ofstream.open

I'm trying to create a program that lets a user create a file through the terminal that also includes details such as the author, the intended target and a short message. What I want to do though is not be always constantly stuck with a .txt extension or a .docx extension if that's possible, I don't know I haven't tried it yet. But what I want to do is have the user input a file name and a file extension where you would usually type the default file name and default file extension. I don't know if that's possible or not but this is what I've come up with so far. Your feedback is greatly appreciated. Thank you! I know the Writer.open part code will look really goofy and it is because it doesn't work...yet! :)

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
  #include <iostream>
  #include<iomanip>
  #include <string>
  #include <windows.h>
  #include <fstream>
  using namespace std;
  
  int main()
  {
  string username;
  string target;
  string message;
  string filename;
  string ext;
  
  cout << "Input Username: ";
  cin >> username;
  cout << "Input Target: ";
  cin >> target;
  cout << "Input Message: ";
  cin.ignore();
  getline (cin, message);
  cout << "Input Desired File Name: ";
  getline (cin, filename);
  cout << "Input Desired File Extension: ";
  getline (cin, ext);
  
  ofstream Writer;       
  Writer.open (filename"."ext);
  Writer << "To: " << target;
  Writer << endl;
  Writer << "From: " << username;
  Writer << endl;
  Writer << endl;
  Writer << message;
  Writer << endl;
  Writer << endl;
  Writer << "--------------";
  Writer << endl;
  Writer << "END OF MESSAGE";
  Writer << endl;
  Writer << "--------------";
  Writer.close();
  cout << endl; 
  cout << endl;
  system("pause");
  return 0;
  }


Topic archived. No new replies allowed.