I want to use std::distance to find the index of my element.
here is the code:
#include <iostream>
#include <map>
#include <iterator>
#include <string>
using namespace std;
int main() {
std::map<int, std::string> m = {{1, "huang"}, {2, "wei"}, {3, "pu"}};
auto it = m.find(2);
cout << std::distance(it, m.begin()) << endl; // struck here
cout << std::distance(it, m.end()) << endl;
}
but i found the code is struck in cout, what's the problem with my code?