stuck in file loading


Having file with strings specified like below
Ex: test.txt

test1=abc
test2=vzxc
test3=agda

test4/ddf=cat
testa44/addf=boy
...
..

i want to store the above file contents into maps
from starting to space store into one map and after then another map.

thanks in advance.





space or newline ?

is test1=abc a single string ? for map1

and test4/ddf=cat for map2 ?
store the strings in map1 untli space in file , after then store into map2
i did this but ..

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
while(std::getline(in,line))                
{		
	int po = lines.find('/'); 	 
	if(po != string::npos) {

			int pos = line.find('=');
			if(pos != string::npos)
			{
			 m_k = line.substr(0, pos);
			 m_v = line.substr(pos + 1, string::npos);
			 map1[m_k] = m_v;
			}
	}else {
			int pos = line.find('=');	
			if(pos != string::npos ) 
			{
				m_k = line.substr(0, pos);
				m_v = line.substr(pos + 1, string::npos);
				map2[m_k] = m_v;
			}
	}				
}	


this is not what i want exactly , if space exists in a line then starts load into map2.
any help ?
strings are separated by space(s)
you can put the size of map1 and map2 at the beginning of the file.
you can use xml deserialization so you are having a property name and a value , etc.
you dont need the = , as long it is separated by a single space.
You can switch the maps like so:
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
bool is_map1 = true;
while(std::getline(in,line))                
{
	if(is_map1)
		is_map1 = !line.empty();

	if(line.empty()) // Note: ignore empty line
		;
	else
	{
		auto &cur_map = is_map1 ? map1 : map2; // Note: select map

		int po = lines.find('/'); 	 // ???
		if(po != string::npos) 	 // ???
		{

				int pos = line.find('=');
				if(pos != string::npos)
				{
				 m_k = line.substr(0, pos);
				 m_v = line.substr(pos + 1, string::npos);
				 cur_map[m_k] = m_v;
				}
		}
	}
}
Topic archived. No new replies allowed.