H
He Shiming
Hi Folks,
I've been using map<wstring, set<wstring> > to manage the internal
string-value pairs in my program. Lately, I discovered that the set<wstring>
doesn't preserve the insertion order when I try to fetch values. Here is
what I do to push values into the map:
for (...) { // inserting wstring values in a predefined order
mymap[L"Field"].insert(L"Stuff");
}
And I'm trying to read out values by:
set<wstring> sszwContent = mymap[L"Field"];
set<wstring>::const_iterator si;
for(si = sszwContent.begin(); si!=sszwContent.end(); ++si)
;// output "si" as a wstring
It's wierd that the order of output got messed up and it appears that the
output order isn't really random. But it's just not the insertion order I
wanted. How can I keep the insertion order in this scenario? Or is it me
who's messed up the order somewhere else?
Thanks and best wishes,
I've been using map<wstring, set<wstring> > to manage the internal
string-value pairs in my program. Lately, I discovered that the set<wstring>
doesn't preserve the insertion order when I try to fetch values. Here is
what I do to push values into the map:
for (...) { // inserting wstring values in a predefined order
mymap[L"Field"].insert(L"Stuff");
}
And I'm trying to read out values by:
set<wstring> sszwContent = mymap[L"Field"];
set<wstring>::const_iterator si;
for(si = sszwContent.begin(); si!=sszwContent.end(); ++si)
;// output "si" as a wstring
It's wierd that the order of output got messed up and it appears that the
output order isn't really random. But it's just not the insertion order I
wanted. How can I keep the insertion order in this scenario? Or is it me
who's messed up the order somewhere else?
Thanks and best wishes,