i have some decimal numbers and want to put them hexadecimal in a string stream. Every Hex number should consist of 2 chars^^. I can't find a flag for it.


should be

#include <cstdio>
#include <iostream>
#include <sstream>
#include <string>
#include <iomanip>

using namespace std;

int main (){

 int number = 16;
 string test;

 stringstream out (stringstream::in | stringstream::out);

 for (int i = 0; i < 255; i++){
 	out << hex << i << "__";

 test = out.str();
 cout << test;

return 0;

With sstream-hex you have to add the zero.

Something like:

vector<string> test; //or array, doesn't matter
if(test[i].size() < 2)
  test[i].insert(0, "0");

I often zero pad things like this:

std::string ZeroPad(const char num, const unsigned int rep)
	std::stringstream Filled;
	Filled << std::setfill('0') << std::setw(rep) << num;
	return Filled.str();

but maybe inserting a '0' like MosaicFuneral said is more appropriate in this case?