Sign in to follow this  
cyberflame

filenames determined in program

Recommended Posts

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

using namespace std;

main()
{
cout << "Enter the your name." << endl;
string UserName;
getline(cin, UserName);
fstream UserNameFile(UserName.c_str(), ios::out | ios::trunc);

//Put stuff in the file

UserNameFile.close();
}

Share this post


Link to post
Share on other sites
You can find out that sort of information simply by doing a quick search on Google.

For example, you should try "c_str() c++" as your keyword.

This is what I found after about 30 seconds of searching:

const char* c_str() const;

For compatibility with "older" code, including some C++ library routines, it is sometimes necessary to convert a string object into a character array ("C-style string"). This function does the conversion. For example, you might open a file stream with a user-specified file name:

string filename;
cout << "Enter file name: ";
cin >> filename;
ofstream outfile (filename.c_str());
outfile << "Data" << endl;

Tells you pretty much all you need to know right? In just 30 secs of research...!

Remember: Google is your friend!

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this