Split string into key-value pairs using C++
This is a small post. how to get key value pairs form a string which out any using any libraries.if the string is string s ="key1:value1,key2:value2,key3:value3,this is a string which we should parse where key value are seperated with ':' and key value pairs are seperated with ','.#includeiostream #include cstring; #include unordered_map; using namespace std; int main(int arg,char**argv){ string s="key1:value1,key2:value2,key3:value3,"; unordered_mapstring,string;kv ; bool k=0; string key,value; for (int i=0;is.length();i++){ if (s.at(i)==':') k=1; else if(s.at(i)==','){ kv[key] = value; key="";value="";k=0;} else if (k==0) key+=s[i]; else value+=s[i]; } cout<<kv["key1"]'\n'endl; return 0; }form the above program Your can clearly see that the program will parse the string and place the values in an unordered_map class which is s...