EDIT :- How his question is different than Getting a character from a string is returning an unexpected number?
- The technology specified there is C#, not c++.
- The question associates list box, while mine was associating a vector, and string.
I am trying to push a string full of integers with the help of string iterator in my c++ integer vector (vector), but unfortunately when I push the de-referenced string, all I get are some garbage value being pushed in my vector.
I tried searching google for days. Alongside that, I've tried looking documentations, and I've also tried to force convert the de referenced string iterator using (int).
#include <iostream>
#include <vector>
#include <string>
using namespace std;
int main() {
string str = "1234";
vector<int> vec;
for (string::iterator itr = str.begin(); itr != str.end(); ++itr){
vec.push_back(*itr);
}
for (vector<int>::iterator itr = vec.begin(); itr != vec.end();
++itr) {
cout << *itr;
}
return 0;
}
Expected output : 1234
Actual output : 49505152