Using Dev-C++

Im a newbie to c++

Is it possible to save files using a variable as the filename.

What i want to do is setup a text based program like a mud and be able to go from room to room and have it display room discription and available exits.
Only way i can think to do this is have a file for each room and have the code open/read or write/close each time i enter a new room.

Problem is i cant work out how to set this up any help would be greatly appreciated.

I only need the syntax for opening a file with a variable

Using Dev-C++

Im a newbie to c++

Is it possible to save files using a variable as the filename.

What i want to do is setup a text based program like a mud and be able to go from room to room and have it display room discription and available exits.
Only way i can think to do this is have a file for each room and have the code open/read or write/close each time i enter a new room.

Problem is i cant work out how to set this up any help would be greatly appreciated.

I only need the syntax for opening a file with a variable

you need to take the c++ string and turn it into a c string

example:

#include<iostream>
#include<fstream>
#include<string>
using namespace std;

int main() {
string fn;
ifstream fin;
cout << "enter file name: ";
cin >> fn;
fin.open(fn.c_str());
.
.
.
}

#include <iostream.h>
#include <fstream.h>
//...
char filename[255];
ifstream infile;
cout<<"File name : ";
cin.getline(filename,255);
infile.open(filename);
//...
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.