How can I convert a vector of integers to a vector of characters?

I've tried:
1
2
3
4
vector<int> integerarray;
vector<char> chararray;
for(count=0;count<integerarray.size();count++)
	chararray[count] = integerarray[count];


But all it does is put in a bunch of 0s in the chararray.

EDIT-Ok now it works and it couts all the numbers when I use int(chararray), but if I take out the int, I thought it should display the asciivalue, but it just displays blanks
Last edited on
Your assignment is backwards. >_>
you gotta be kidding me *facepalm* I am so stupid.
You can initialize (or assign to) a std::vector<> using a pair of iterators.

1
2
3
4
5
std::vector<int> integerarray ;
// ....
std::vector<char> chararray( integerarray.begin(), integerarray.end() ) ;
// ...
chararray.assign( integerarray.begin(), integerarray.end() ) ;
Topic archived. No new replies allowed.