I have the next code:
ofstream dataIndex;
dataIndex.open("file");
index="2222";
std::stringstream sstr1;
sstr1<<index<<'1';
sstr1<<setfill('0')<<setw(index.length()-9);
string index1= sstr1.str();
dataIndex<<index1;
dataIndex.close()
and i hope the result:
2222100000
but only i get
22221
without zeros? what happened?
manipulators are applied to the stream the same as input. For them to take effect they need to be applied first. For example here is how you would fill zeros on a string stream.
If you want to fill differently then simply add in a direction manipulator like
std::left,std::right, etc.