Home » Extra libraries, Code snippets, applications etc. » U++ users applications in progress and useful code snippets, including reference examples! » Trouble iterrating over VectorMap<String, String> - general StoreIniFile
Re: Trouble iterrating over VectorMap<String, String> - general StoreIniFile [message #18549 is a reply to message #18548] |
Tue, 07 October 2008 21:39   |
 |
mirek
Messages: 14261 Registered: November 2005
|
Ultimate Member |
|
|
blueapples wrote on Tue, 07 October 2008 15:22 | I am trying to make a general StoreIniFile function that will take a VectorMap<String, String> and save it's contents as a INI formatted string.
This is what I have so far, which fails on the call to cfg.Get() with a failed assert like "i > 0 && i < size"...
int StoreIniFile(VectorMap<String, String> cfg, const char *filename) {
int i = 0;
String cfgstring;
Vector<String> keys = cfg.GetKeys();
|
This would "pick" cfg, effectively destrying its content. (Same applies to the function parameter cfg!) You can use
[code]
const Vector<String>& keys = cfg.GetKeys();
[/quote]
if you need to "see" keys as Vector, anyway, I believe you really do not:
int StoreIniFile(const VectorMap<String, String>& cfg, const char *filename) {
int i = 0;
String cfgstring;
if(cfg.GetCount() > 0) {
PromptOK(Format("found %i items", cfg.GetCount()));
for(i = 0; i < cfg.GetCount(); i++)
{
PromptOK(Format("Key %i: %s Value: %s", i, cfg.GetKey(i), cfg[i]));
cfgstring << cfg.GetKey(i) << "=" << cfg[i] << "\n";
}
}
//SaveFile(filename, cfgstring);
return true;
}
Also notice the change in function signature...
Quote: |
I seem to have some gaps in my C++ knowledge,
|
Actually, you need U++ knowledge here, this is not quite a traditional way of C++.
Mirek
|
|
|
Goto Forum:
Current Time: Mon Jun 09 07:04:55 CEST 2025
Total time taken to generate the page: 0.03157 seconds
|