I want to write a function that accepts one string and one integer and return concatenation of both but i always want integer to be fixed width say 3.
e.g. if string is "jamesbond" and integer is 7, function should return a string "jamesbond007". How to do it in C++ ?
Note: I dont want to write if else and other conditional statements. Thank you.
Yes, this is one solution but i dont want to do it since it requires a lot of code. What if the fixed width is 10 then i will be writing 10 statement. Is there any direct function in cpp that can take an integer and return a fixed width integer ?
void concatenate(string &s, int x, int w) {
if(w==0) return;
concatenate(s,x/10,w-1);
s.push_back('0'+x%10); }
str s2= str("i");
int l2=strlen(s2);
str dummy=("0");
make_dummy_of_length_w-l2();
return s1+dummy+s2;