Computer Forums

Member Login

Remember Me? Sign Up! | Forgot Password
 
Slogan
 
Computer Forums > Programmers Lounge > Programming Discussions » I'm not sure how to word the title of the thread...
Closed Thread
Old 12-13-2006, 02:04 AM   #1 (permalink)
 
Newb Techie

Join Date: Jan 2006

Posts: 20

Chaosenemy

Send a message via Yahoo to Chaosenemy
Default I'm not sure how to word the title of the thread...

Okay, I know I just made another topic like 5 minutes ago, but... I've already got another question.

Basically I'm wondering how you can use outside files with a C++ console application. Like for instance have your EXE file and then a TXT file that the program accesses for certain values.

Example:
{
You have a text game of some kind, a text game that saves your progress so that when you exit it, you don't have to start all over. Your progress would be saved in a text file, holding values like "playerName", "playerScore", etc that will be accessed when running the program again.
}

So is there a way to do this? Make your program call on another file to define certain variables?

(This could also be useful for changing other game values to make it easier/harder to beat a.k.a. modding, without having to recompile the whole thing.)
Chaosenemy is offline  
Old 12-13-2006, 06:35 AM   #2 (permalink)
baronvongogo's Avatar
 
Master Techie

Join Date: May 2005

Location: UK

Posts: 2,749

baronvongogo is on a distinguished road

Default

yes using #include<fstream> I think...

http://www.cplusplus.com/doc/tutorial/files.html

here's a link to some tutorials I did write a RPG game all in text, and I had to read and write from a file it worked fine just don't have the code anymore .
__________________
baronvongogo is offline  
Old 12-13-2006, 02:33 PM   #3 (permalink)
 
Super Techie

Join Date: Sep 2005

Posts: 341

hillbillybob

Default

If your talking like a config file or INF file....ya, you will need to read the file, parse it to pick out the data you want, bind that to your variables so that your program can run it with the new values. I can do it in C#, but im not good enough to give you some example code in C++. Sorry.
__________________
The greatest measure of a nation is not it\'s army or economy, but by how many people are trying to get in, and how many people are staying!!
Guns, Guts, and Alcohol made America free.
Born American, Die American
Ubuntu - it\'s all about the bun\'s baby!!!
hillbillybob is offline  
Old 12-13-2006, 02:59 PM   #4 (permalink)
 
Super Techie

Join Date: Jul 2004

Posts: 375

Nikkon

Default

You can google C++ file handling tutorials and get a ton of examples. Its a pretty easy concept. You can also think about doing some sort of encryption on the data that you store in the file (so that the user does not open the file and edit it to advance them selves in the game). You can google binary encryption if you are instrested in that. (usually just a shift left or shift right of 4 bits of each ascii character).
__________________
AMD 3800+ X2
Zalman CNPS7000B CPU Heatsink/Fan
ASUS A8N Premium
2 GB G. Skill DDR 400 (2 X 1 GB)
1 GB Ultra DDR 400 (2 X 512 GB)
eVGA 7800GT 256MB
120 GB seagate HD (7200RPM)
80 GB Seagate HD (7200RPM)
Sound Blaster Audigy 2 Platium ZS Sound Card
Logitec z5300 5.1 THX certified speaker
Medusa 5.1 Headphones
ATI TV turner card
DVD Drive
CD Burner Drive
Razer Copperhead Gaming mouse
Nikkon is offline  
 
Closed Thread

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On