online compiler and debugger for c/c++

code. compile. run. debug. share.
Source Code    Language
#include <iostream> #include <vector> #include <map> #include <algorithm> void sortString(std::vector<std::string>& arr, std::map<int, std::vector<std::string>>& mp) { std::sort(arr.begin(), arr.end()); for (int i = 0, sz(arr.size()); i < sz; ) { std::string str = arr[i]; std::vector<std::string> indices; indices.push_back(arr[i]); indices.push_back(arr[i+1]); /*std::cout << "i " << i << " key " << (str.at(0)) << " value " << arr[i] << " - " << arr[i+1] << std::endl; */ mp.insert(std::make_pair((int)(str.at(0)), indices)); i = i+2; } return; } void printMapElements(std::map<int, std::vector<std::string>> mp) { std::cout << "\nIndices Pair: \n"; for (auto itr = mp.begin(); itr != mp.end(); itr++) { std::cout << "Key:ASCII " << itr->first << " "; std::vector<std::string> idx = itr->second; std::cout << "Value: " << idx[0] << " " << idx[1]; std::cout << "\n"; } return; } void printArray(std::vector<std::string> arr) { for (int i = 0; i < arr.size(); i++) std::cout << arr[i] << " "; std::cout << std::endl; } int main() { std::vector<std::string> str = { "Hello", "Colourful", "World", "How", "Cute", "Watch" }; std::map<int, std::vector<std::string>> mp; std::cout << "Before Inserting into Map: \n"; printArray(str); sortString(str, mp); std::cout << "\nSorted array: \n"; printArray(str); printMapElements(mp); return 0; }

Compiling Program...

Command line arguments:
Standard Input: Interactive Console Text
×

                

                

Program is not being debugged. Click "Debug" button to start program in debug mode.

#FunctionFile:Line
VariableValue
RegisterValue
ExpressionValue