FIle writing issue

I just started c++ programming, and am trying to make a very simple database just to exercise some of the concepts i've learned. I am trying to make a file for each user who enters in the data. By the way It is far from complete, I have some other functions of the program i will work on after I finish this. Here is my code

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
             cout << "FILE NAME: ";
             getline(cin, File);
             cout << "\n";          
             cout << "NAME: ";
             getline(cin, Name);
             cout << "\n";
             cout << "AGE: ";
             getline(cin, Age);
             cout << "\n";
             cout << "YEARS EMPLOYED: ";
             getline(cin, Ye);
             cout << "\n";
             cout << "EXTRA COMMENTS: ";
             getline(cin, Com);
             cout << "\n";
             cout << "PHONE NUMBER: ";
             getline(cin, Phone);
             cout << "\n";
             ofstream DATABASE;
             DATABASE.open(File);
             DATABASE << "NAME:" << Name << "\n";
             DATABASE << "AGE:" << Age << "\n";
             DATABASE << "YEARS EMPLOYED: " << Ye << "\n";
             DATABASE << "EXTRA COMMENTS: " << Com << "\n";
             DATABASE << "PHONE NUMBER: " << Phone << "\n";
             DATABASE << "-------------\n\n";
             DATABASE.close();
            

Ok so when I try to compile this code, I get an error on the [code] DATABASE.open(File);[\code] What I am trying to do is use the input from the user and turn that into the name of the file. How do I use user input to be used as my file name???
I get an error on the DATABASE.open(File);
¿what error?
You need the name of the file in quote DATABASE.open("File.txt");
If you are wanting to constantly change this file name then i think you need to add a special function on the end of the string name otherwise you'll get a compile error.

EDIT: the function needed might be this .c_str() however i'm not sure (found this in another post on this forum)
DATABASE(stringname.c_str());

P.S. it's [ / code ] to end the example code properly. :)
Last edited on
Topic archived. No new replies allowed.