Now I'm trying to write a save file, where part of the filename is a variable that you type in(your character's name), so each character generates its own unique save file. Here's what I have so far:
I need a way to add the value of input before the ".sav" in the filename, is there a simple way to do this?
cout<<"Who are you? ";
ofstream a_file (".sav");
a_file<<"<Save game info for this character...>";
Assuming input is a string object, it's trivial:
ofstream a_file (input + ".sav");
Hrm, when trying that, I get this error:
60 E:\Dev-Cpp\My Crap\New Adventure RPG\Adventure RPG.cpp no matching function for call to `std::basic_ofstream<char, std::char_traits<char> >::basic_ofstream(std::basic_string<char, std::char_traits<char>, std::allocator<char> >)'
Heheh, silly me. I keep forgetting to do that:
A C-style string is expected, but after the concatenation all you have is a string object. So you need to call the c_str member function to get a C-style string. :)
ofstream a_file ( (input + ".sav").c_str() );
Thank you much! That works beautifully! Now, all I need to learn is how to make a @ dude that can move around, and I'm well on my way :)
(I've decided to go after my roguelike dream again)
You gonna use the arrow keys for that? I'd recommend this FAQ link then
Yes, I have started a new thread in the games section for this, located here: http://cboard.cprogramming.com/showt...430#post591430