having trouble

i want to get the user to name the file but i dont know how to do that i know how i can name it but i want the user to name it. heres the source

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
#include <iostream>
#include <fstream>
#include <string>
#include <cstdlib>

using namespace std;
int main()
{
	string name;
	string date;
	cout << "client name: ";
	getline(cin, name);
	cout << "\n";
	cout << "date: ";
	getline(cin, date);
	cout << "\n";
	cout << "enter notes after ...\n";
	ofstream fout;
	fout.open("/home/johnsuess/Desktop/clientfiles/"name".text", ios::app);
	string close;
	int x = 1;
	int y = 2;
	while (x != y)
	{
		string text;
		cout << "...";
		getline(cin, text);
		cout << "[[";
		string deter;
		getline(cin, deter);
		if (deter == "close")
		{
			x++;
		}
		else
		{
			fout.close();
		}
	}
	return 0;
} 
You'll need one more string variable, call it something obvious like "FileName". Then some where above Line 19:
 
FileName = "/home/johnsuess/Desktop/clientfiles/" + name + ".text";

and Line 19 should look something like:
 
fout.open(FileName.c_str(), ios::app);
Thanks but what does FileName.c_str() and how can I learn more about it. that syntax looks unfamiliar.
.c_str() converts a string to a cstring
http://www.cplusplus.com/reference/string/string/c_str/

it isn't necessary here you can use fout.open(FileName, ios::app);
Topic archived. No new replies allowed.