I have a string "codeforces" and now when i am storing characters of this string as key in an unordered map and index of occurrence of that character in a vector inside unordered map as value , then it is not showing correct indexes .
In this string "codeforces" character 'c' is occurring at index 1 and 8 , i would like to store character c as key in map and corresponding indexes of occurrences inside vector as value in unordered map . But when i am doing this it is not showing correct value . Can any body tell me why is this happening ?
#include <iostream>
#include <unordered_map>
#include <vector>
#include <algorithm>
#include <string>
using namespace std;
int main(){ 
    string x = "codeforces";
    unordered_map<char,vector<int>> data;
    for(int i = 1;i <= x.size();i++){
        data[x[i]].push_back(i);
    }
    for(auto it : data){
        if(it.first == 'c'){
            vector<int> out = it.second;
            for(int j = 0;j < out.size();j++){
                cout<<out[j]<<" ";
            }
            cout<<endl;
        }
    }
    return 0;
}
Output should be like this (for character 'c') -> 1 8 .
But it is showing -> 7 .
 
    