Dev-C++ using variables in functions?

Soldato
Joined
2 May 2004
Posts
19,950
Hi,

I have this code to backup my save-game(s):

Code:
std::ifstream ifs("Craig06.usr", std::ios::binary);
std::ofstream ofs("Craig06Backup.usr", std::ios::binary);

ofs << ifs.rdbuf();

Rather than using the name Craig06Backup.usr I'd like to be able to do Craig06<current_date>.usr to avoid it overwriting the previous backup.

So, any idea how I can use variables in that bit of coding please?

Thanks,
Craig.
 
im not sure as i have only just started c++ but couldn't you do something like:

(("craig06 %s", <current date>), std.....)

not sure if this would work in c++ but this is the java equivalent:

(("craig06" + <current date>), std....)

dunno if any of the above will work, but tis worth a try

daven
 
This should work...
Code:
char date_string[64];
time_t time_utc = time(NULL);
tm *time_local = localtime(&time_utc);
strftime(date_string, sizeof(date_string), "%Y%m%d-%H%M", time_local);
std::ofstream ofs((std::string("craig06 ") + std::string(date_string) +
        std::string(".usr")).c_str(), std::ios::binary);
 
Back
Top Bottom