I was wondering if its possible to specify the name of a file being created with a variable yet still specify the extension for the file.
Example:

string name;
cin >> name;

ofstream myfile;
myfile.open(name".sta", ios::out);

i was wondering if you could do something of the sort

i know you can do one or the either but i don't know if its possible to do both at the same time.

Nevermind i found the solution, i just had to take the same string and append .sta to it.

Of course. Since myfile is ofstream it is not necessary to specify ios::out because that's what ofstream does anyway.

name += ".sta";
myfile.open(name.c_str());

ohh, mybad. Yea your right, it was supposed to be fstream

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.