So I have a problem at hand and would like to know the most efficient way to go about it.
I would like to break down a integer into part, so say I have 1234
I would like to break it into 12
and 34
or if I have 123
I would like it to be 1
and 23
.
My original idea is to convert to string as I would in some modern programming language, then get the length of the string and then the substring, but I do not feel this is a good way to do it in C++.
Please I would like suggestions on how to go about solving this issue, I already have a function that would help me get the number of digits from an integer.
template <class T> int getDigits(T number) {
int digits = 0;
while(number ){
number /= 10;
digits++;
}
return digits;
}