Sign in to follow this  
Dan

Any Way...

Recommended Posts

Is there anywya to make a program in C++, that can save data to a disk (like an ini file), and read information.

Ex.

A wrestling program.

Select option: (1 for edit, 2 for new, 3 for delete) 1

then comes up all of his points for the year.

Is this possible?

dk

Share this post


Link to post
Share on other sites

Sure. That's why the fstream classes (ifstream, ofstream, and iofstream) and most of <cstdio> exist. Even without those, you could use the platform I/O API or, on many platforms, redirect the standard I/O streams to files.

But it's important to know exactly what you need the program to do. If all you need is a way to persist the information, you can overload operator<<() and operator>>() to (de)serialize the data without too much trouble. If you also need to be able to change the on-disk data (or even read it) or if it's fairly complex you would probably want a more structured format (INI, XML), but that would require at least a parser for the read side (you could munge it manually for the writes). If you're really trying to make a database, use a database. Wrap it in a C++ front-end if you like.

Edited by jcl

Share this post


Link to post
Share on other sites

you can't beat python for ease of use and fast results.

to write to a file, this is as simple as it gets

file = open("filesw.ini", "w")
file.write("text to be written, gos here")

Edited by shanenin

Share this post


Link to post
Share on other sites
you can't beat python for ease of use and fast results.

to write to a file, this is as simple as it gets

file = open("filesw.ini", "w")
file.write("text to be written, gos here")

<{POST_SNAPBACK}>

C++ isn't much more complex for that particular example. It just has more boilerplate.

#include <fstream>
#include <iostream>

int main()
{
std::ofstream fout ("filename");
fout<<"Some text"<<std::endl;
}

Given the description of the problem, I almost think a simple spreadsheet would be the best option.

Share this post


Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
Sign in to follow this