i'm trying to find a solution to the following problem:
i converted chars into int. for example char 'a' becomes int '97' (using ascii). then i saved those integers in a vector. no problem so far.
what i'm trying to do now is to get 3 digits for every vector element. for example 'a' becomes '097'. so i'm trying to put zeros in front of elements that only have 1 or 2 digits.
That is, if by "get 3 digits" you mean print 3 digits for every vector element. If you want to somehow have the leading zeroes stored in the variable, then you will have to store the ints as std::strings for example.
my actual problem is encoding a word (for example the word "code") into numbers (so that "code" becomes "099 111 100 101"). later i want to reconstruct the word out of the safed number (in this case 099 111 100 101).
my plan was to assign 3 digits to every character in order to avoid mixing up the characters. normally i would store every character as a vector element, but i need to operate with the whole "code number".
by the way the project i'm working on is secret sharing based on the chinese remainder theorem.
but i need to operate with the whole "code number"
You can store the whole code as a vector of strings (or alternatively as one string). To reconstruct the original word, you can convert each string (or group of three characters) back to numeric (the <sstream> header can help you with this) and then from numeric back to the character.