Hi,
I have a data I want to make fix length records Like suppose:-
one two three four
one two three
one
In this case the fixed length should be of the maximum string length which is of the first line. My code below is giving creating faulty fix lengths. Can somebody help.
so the output will be like this
one two three four
one two three
one
Here is my code and I have to do it with multimap:-
#include <iostream>
#include <map>
#include <string>
#include <algorithm>
using namespace std;
bool pairStringComp(pair<string,int> i,pair<string,int> j){ //compare pairs by string size
return i.first.size()<j.first.size();
}
int main(){
multimap<string,int> mymm;
multimap<string,int>::iterator it;
mymm.insert(pair<string,int>("x1adsf",50));
mymm.insert(pair<string,int>("y12",100));
mymm.insert(pair<string,int>("y12",150));
mymm.insert(pair<string,int>("y12",200));
mymm.insert(pair<string,int>("z1234",250));
mymm.insert(pair<string,int>("z1234",300));
int maxStringSize=max_element(mymm.begin(), mymm.end(),pairStringComp)->first.size();
for (it=(mymm.begin()); it!=(mymm.end()); it++){ //cout pairs sorted lexicographically
cout.width(maxStringSize);
cout<<it->first<<"-"<<it->second<<endl;
}
return 0;
}
Thanks