flat files

Hullo every one
I have searched in google but with no clear success.
I am new to c++ programming
but i want to create a flat file using c++ codes that can be used to store a few records.
any help, codes, libraries,templates, tutorials and advice is most welcome
Thanks in advance
you mean http://en.wikipedia.org/wiki/Flat_file_database ?
It's a simple text file. You write it like any other text file. just put tabs and newlines at the right places.
hi hamsterman
thanks for your fast response.
yes i mean like a txt file
but the program should be able to edit any record,read any record,delete a particular record and add a record to the existing database.
You will need to read about fstream. In this site there is a clear reference.

A class could be used to have a handle to your .txt file. Then you could read a file line by line and store these lines into a structure of your choosing i.e.

You could use a structure like vector<vector <std::string> > to store you file, where the index to the first vector will give you your entire row (record) and the index to the second vector could give you a particular field :

For example you can split a delimited line with a function like this :

1
2
3
4
5
6
7
8
9
10
11
const std::vector<std::string> CUtilities::splitString(const std::string & string_in,const char & delim_in)
	{
		std::stringstream ss(string_in); 
		std::string item; 
		std::vector<std::string>elems;
		while(std::getline(ss, item, delim_in))
		{ 
			elems.push_back(item); 
		}
		return elems;
                }


And then use an enum to access the actual field. Then you can abstract the functions you mentioned (edit any record,read any record,delete a particular record and add a record to the existing database)

And you are done! :)
thanks silvermaul
let me check this out about vectors
thanks alot
Topic archived. No new replies allowed.