 <p>Check out e.g. the <a href="http://en.cppreference.com/w/cpp/string/byte/strtok" rel="nofollow"><code>strtok</code></a> function. Use it in a loop to split at the <code>'&amp;'</code> to get all the key-value pairs into a vector (for example). Then go though the vector splitting each string (you can use <code>strtok</code> again here) at the <code>'='</code> character. You can put the keys and values in a <code>std::map</code>, or use directly.</p> <p>For an even more C++-specific method, use e.g. <a href="http://en.cppreference.com/w/cpp/string/basic_string/find" rel="nofollow"><code>std::string::find</code></a> and <a href="http://en.cppreference.com/w/cpp/string/basic_string/substr" rel="nofollow"><code>std::string::substr</code></a> instead of <code>strtok</code>. Then you can put keys and values directly into the map instead of temporary storing them as strings in a vector.</p> <p><strong>Edit:</strong> How to get the last pair</p> <p>The last key-value pair is not terminated by the <code>'&amp;'</code> character, so you have to check for the last pair <em>after</em> the loop. This can be done by having a copy of your string, and then get the substring after the last <code>'&amp;'</code>. Something like this perhaps:</p> <pre><code>char *copy = strdup(data); // Loop getting key-value pairs using `strtok` // ... // Find the last '&amp;' in the string char *last_amp_pos = strrchr(copy, '&amp;'); if (last_amp_pos != NULL &amp;&amp; last_amp_pos &lt; (copy + strlen(copy))) { last_amp_pos++; // Increase to point to first character after the ampersand // `last_amp_pos` now points to the last key-value pair } // Must be free'd since we allocated a copy above free(copy); </code></pre> <p>The reason we need to use a copy of the string, if because <code>strtok</code> modifies the string.</p> <p>I still would recommend to you use C++ strings instead of relying on the old C functions. It would probably simplify everything, including you not needing to add the extra check for the last key-value pair.</p>