|
|
Search
|
|||||||
| Home | Register | Downloads | FAQ | Members List | Calendar | Arcade | Mark Forums Read |
![]() |
|
|
LinkBack | Thread Tools | Display Modes |
|
|
#1 (permalink) |
|
Effulgent Plasma Chemist
![]() ![]() ![]() Join Date: Jul 2001
Posts: 271
|
Implementing a rudimentary save system
Greetings, So I have been messing around again with c++ after my life settled the hell down. I am writing a text based adventure game (yes, really ), and I want to store the text is seperate notepad files for easy reference and editing.Here is what I have: Code:
void story (string stf)
{
string line;
string stftxt = ".txt";
stftxt.insert(0,stf);
ifstream storyfile;
storyfile.open (stftxt);
if (storyfile.is_open())
{
while (! storyfile.eof() )
{
getline (storyfile, line);
cout << line << endl;
}
storyfile.close();
}
else cout << "Unable to open file";
}
Anyways, how do I dynamically open different files depending on a value passed to the function "story"? Any ideas would be most helpful. Thanks, TastEPlasma EDIT: Aww hell, I originally started to type this about a rudimentary save system, but I finally figured all that out (how to read/write arrays to a .txt file). Cant change the threads title now though. :-(
__________________
Computer Specs: Hers: *c2q 9550 (2.83) @ 3.4Ghz *4GB OCZ Reaper DDR2-1066 5-5-5-15 *Sapphire Radeon 4870 w/ 1GB *SB Audigy SE *DFI LANParty DK X48-T2RS *700W OCZ GXS *320GB WD SATA2 *SBC DSL ISP *Samsung 906cw His: *c2d 6320 (1.86) @ 3.3Ghz *2GB OCZ flex DDR2-800 4-4-5-15 @ 950 *BFG 8800GTX @ 632core, 2000mem *SB Audigy SE *eVGA 680i (122-CK-NF63-TR) *700W OCZ GXS *400GB WD sata2 *SBC DSL ISP *Samsung 226bw *Nautilus 500 water cooling system on gpu, cpu, and mem
Last edited by TastEPlasma; October 14th, 2009 at 00:16.. Reason: Screwed up thread title |
|
|
|
| Advertisement | [Remove Advertisement] | ||
|
|
|
|
#3 (permalink) |
|
Effulgent Plasma Chemist
![]() ![]() ![]() Join Date: Jul 2001
Posts: 271
|
Unfortunately not. The primary problem is that I cant use a variable with the function file.open. i.e. This is valid: Code:
storyfile.open ("story.txt");
Code:
storyfile.open (story);
__________________
Computer Specs: Hers: *c2q 9550 (2.83) @ 3.4Ghz *4GB OCZ Reaper DDR2-1066 5-5-5-15 *Sapphire Radeon 4870 w/ 1GB *SB Audigy SE *DFI LANParty DK X48-T2RS *700W OCZ GXS *320GB WD SATA2 *SBC DSL ISP *Samsung 906cw His: *c2d 6320 (1.86) @ 3.3Ghz *2GB OCZ flex DDR2-800 4-4-5-15 @ 950 *BFG 8800GTX @ 632core, 2000mem *SB Audigy SE *eVGA 680i (122-CK-NF63-TR) *700W OCZ GXS *400GB WD sata2 *SBC DSL ISP *Samsung 226bw *Nautilus 500 water cooling system on gpu, cpu, and mem
|
|
|
|
|
|
#5 (permalink) |
|
Effulgent Plasma Chemist
![]() ![]() ![]() Join Date: Jul 2001
Posts: 271
|
I do get an error, it refuses to compile. I think it is a syntax error. "cannot convert parameter 1 from 'std::string' to 'const wchar_t *'"
__________________
Computer Specs: Hers: *c2q 9550 (2.83) @ 3.4Ghz *4GB OCZ Reaper DDR2-1066 5-5-5-15 *Sapphire Radeon 4870 w/ 1GB *SB Audigy SE *DFI LANParty DK X48-T2RS *700W OCZ GXS *320GB WD SATA2 *SBC DSL ISP *Samsung 906cw His: *c2d 6320 (1.86) @ 3.3Ghz *2GB OCZ flex DDR2-800 4-4-5-15 @ 950 *BFG 8800GTX @ 632core, 2000mem *SB Audigy SE *eVGA 680i (122-CK-NF63-TR) *700W OCZ GXS *400GB WD sata2 *SBC DSL ISP *Samsung 226bw *Nautilus 500 water cooling system on gpu, cpu, and mem
|
|
|
|
|
|
#6 (permalink) | |
|
Global Moderator
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() Join Date: Jul 2001
Location: South Carolina, USA
Posts: 6,824
|
Quote:
Code:
storyfile.open (story.c_str()); |
|
|
|
|
|
|
#7 (permalink) |
|
Effulgent Plasma Chemist
![]() ![]() ![]() Join Date: Jul 2001
Posts: 271
|
Absolutely awesome. c_str - C++ Reference Link for info. Thank you so much, this has been plaguing me for a couple of hours now. It works now. :-DDD
__________________
Computer Specs: Hers: *c2q 9550 (2.83) @ 3.4Ghz *4GB OCZ Reaper DDR2-1066 5-5-5-15 *Sapphire Radeon 4870 w/ 1GB *SB Audigy SE *DFI LANParty DK X48-T2RS *700W OCZ GXS *320GB WD SATA2 *SBC DSL ISP *Samsung 906cw His: *c2d 6320 (1.86) @ 3.3Ghz *2GB OCZ flex DDR2-800 4-4-5-15 @ 950 *BFG 8800GTX @ 632core, 2000mem *SB Audigy SE *eVGA 680i (122-CK-NF63-TR) *700W OCZ GXS *400GB WD sata2 *SBC DSL ISP *Samsung 226bw *Nautilus 500 water cooling system on gpu, cpu, and mem
|
|
|
|
|
|
#8 (permalink) | |
|
Global Moderator
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() Join Date: Jul 2001
Location: South Carolina, USA
Posts: 6,824
|
Quote:
![]() Oh, and good to see you around after all these years. Not many of us original members left.
|
|
|
|
|
|
|
#9 (permalink) |
|
Effulgent Plasma Chemist
![]() ![]() ![]() Join Date: Jul 2001
Posts: 271
|
My aim is primarily just to familiarize myself with the data management techniques of OO programming (which, so far, I am loving). I have several progressively grander projects in mind, but I got a lot of basic knowledge to grasp first. I am thinking about making this project modular, since I am halfway there anyway, so if someone wanted they could just write the text files and a single text-based control file that would give the events a flowchart. I figure this is good practice since I am continuing to subdivide the data and function into successively smaller, cleaner pieces. I also want my future projects to be modular as well, so its good practice in that sense too. As for the older members, there is a certain feeling of warmth and nostalgia to see people still kickin around after all these years, eh?
__________________
Computer Specs: Hers: *c2q 9550 (2.83) @ 3.4Ghz *4GB OCZ Reaper DDR2-1066 5-5-5-15 *Sapphire Radeon 4870 w/ 1GB *SB Audigy SE *DFI LANParty DK X48-T2RS *700W OCZ GXS *320GB WD SATA2 *SBC DSL ISP *Samsung 906cw His: *c2d 6320 (1.86) @ 3.3Ghz *2GB OCZ flex DDR2-800 4-4-5-15 @ 950 *BFG 8800GTX @ 632core, 2000mem *SB Audigy SE *eVGA 680i (122-CK-NF63-TR) *700W OCZ GXS *400GB WD sata2 *SBC DSL ISP *Samsung 226bw *Nautilus 500 water cooling system on gpu, cpu, and mem
|
|
|
|
![]() |
| Thread Tools | |
| Display Modes | |
|
|