Cannot print out map items.
std::multimap has a slightly different interface from std::map, you will have to re-write your code to use it. Your compiler, which is likely GCC on Linux, will certainly support it - it is part of the standard and may not be omitted.
Ye i recently found the problem and fixed it, now i'm reading about the multi-maps so i get the hang of they're usage.
EDIT:
By using a std::multimap<string, pair<string, string> > everything went according to plan. Now all the Sections are paired with they're keys, values. Also i toke advantage of your suggestion about the .eof() and replaced it with the while(getline ... Everything is displaying as it should and the syntax isn't any different from the one before.
Here's the code:
And the console output:
A HUGE thanks to you guys for all you've done.
[Edited by - Cha0sBG on August 21, 2010 7:00:03 PM]
EDIT:
By using a std::multimap<string, pair<string, string> > everything went according to plan. Now all the Sections are paired with they're keys, values. Also i toke advantage of your suggestion about the .eof() and replaced it with the while(getline ... Everything is displaying as it should and the syntax isn't any different from the one before.
Here's the code:
SectionData::iterator coniter; in.open( cpath_.c_str( ) ); if( in.fail( ) ) throw "Failed to open file [ " + cpath_ + " ]\n"; string Line, section, key, data; if( in.is_open( ) ) { while( getline(in, Line) ){ bool has_sections = false; bool lineIsSection = false; /* Skip empty lines and lines begining with '#' * To skip lines in the config file just put '#' in front of * the line. that will make the handler skip the line */ if(Line.empty( ) || Line[0] == '#') continue; //remove new lines and partialy new lines rebuild_string(Line, "\r"); rebuild_string(Line, "\n"); if(exist("[", Line) && exist("]", Line)) { has_sections = true; lineIsSection = true; }else{ lineIsSection = false; } if(has_sections && lineIsSection) { SectionStart = find("[", Line ); SectionEnd = find("]", Line); section = Line.substr(SectionStart +1 , SectionEnd - SectionStart -1); continue; } Split = find("=", Line ); KeyStart = find_first_not_empty(Line); KeyEnd = find_first_not_of("=", Line, KeyStart); ValueStart = find_first_not_empty(Line, Split+1 ); ValueEnd = Line.size( ); key = Line.substr( KeyStart, KeyEnd - KeyStart ); data = Line.substr( ValueStart, ValueEnd - ValueStart); //remove all empty spaces from the strings to prevent invalid results section = rebuild_string(section, " "); key = rebuild_string(key, " "); data = rebuild_string(data, " "); SectionContents.insert(std::make_pair(section, std::make_pair(key, data))); } coniter = SectionContents.begin(); while (coniter != SectionContents.end()) { std::cout << "Section [ " << coniter->first << " ]\n"; std::cout << "Key [ " << coniter->second.first << " ]\n"; std::cout << "Data [ " << coniter->second.second << " ]\n\n"; coniter++; } } //Close the file in.close( );
And the console output:
Section [ section1 ]Key [ Key1 ]Data [ 0xF36D ]Section [ section1 ]Key [ Key2 ]Data [ 0x1337 ]Section [ section1 ]Key [ Key3 ]Data [ 0xFDA4 ]Section [ section1 ]Key [ Key4 ]Data [ 0x87LD ]Section [ section2 ]Key [ default ]Data [ config.cfg ]
A HUGE thanks to you guys for all you've done.
[Edited by - Cha0sBG on August 21, 2010 7:00:03 PM]
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement