Trying to create ini file system

I'm trying to make a system that allows me to load, read, write and save ini files.

Ive got this code for my ini class which loads the file and can also save the file.

However I'm not sure on how to prase the text that is being loaded and store the data.

I need it so I can have functions like "string get_value(string section, string key)" as well as functions for creating a new section/key and checking if one exits (eg "bool exists_section(string section) or "bool exists_key(string section, string key)")

I have no idea how to do this. I can probebly put togerther something to get the sections and keys from the file line by line but then how do I store them and how can I "insert" news ones into it?

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
class cl_ini{
	public:
	string file_text;
	bool load(char path[])
	{
	 	file_text.clear(); //clear existing file data

		//load file
	 	string line;
		ifstream file;
		file.open (path);
		if (!file.is_open()) return 0;
		
		//read file line by line
		while(!file.eof())
		{
			getline(file, line);
			pos = line.find(";");
			//write to file string
			file_text += line + "\n";
		}
		file.close();
		return 1;
	}
	
	bool save(char path[])
	{
 	 	 ofstream file (path);
  		 if (file.is_open())
  		 {
    	  	file << file_text;
     		file.close();
			return 1;
		 }
		 else return 0;
    }

	bool exists()
	{
	 	if(!file_text.empty()) return 1;
		else return 0;
	}
};


int main()
{
	cl_ini * ini;
	ini = new cl_ini[32];
	ini[0].load("file.txt");
	
	cout << ini[0].file_text << "\n";
	system("pause");
	return 0;
}
Topic archived. No new replies allowed.