### Ahmed_Hussein_Karam's blog

By Ahmed_Hussein_Karam, history, 6 years ago,

What is the most efficient way to convert an integer to a string in C++?

• -10

 » 6 years ago, # | ← Rev. 4 →   +3 add this library #include  and then write this function string convert (int x){ ostringstream temp; temp << x; return temp.str(); }  Or just use s = to_string(x); where s is string, x is integer
 » 6 years ago, # |   +12 I like to use sprintf() for this kind of situation. char buf[100]; int x = 10123; sprintf ( buf, "%d", x );  buf[] has the value of x in it as string. It's like printf() function, but for strings. Hence the name sprintf(). And yes, we also have sscanf(). char buf[] = "1235"; int x; sscanf ( buf, "%d", &x); 
•  » » 6 years ago, # ^ | ← Rev. 2 →   0 Are there any libraries to be included forthright48?
•  » » » 6 years ago, # ^ |   +3 #include 
•  » » » » 6 years ago, # ^ |   0 Ok thanks