How to convert integer to string in C++



How to convert integer to string in C++..

Answer / Baleandra Tiwari

To convert an integer to a string in C++, you can use std::to_string. Here is an example:

```cpp
#include <iostream>
#include <string>
#include <sstream>

int main() {
int number = 42;
std::ostringstream convert;
convert << number;
std::string result = convert.str();
std::cout << "The integer " << number << " converted to a string is: " << result << "n";
return 0;
}
```

Is This Answer Correct ?    0 Yes 0 No

Post New Answer

More C++ Interview Questions

What are pass by value and pass by reference?what is the disadvantage of pass by value?

1 Answers   Alter,


Write a C++ Program to Find whether given Number is Odd or Even.

1 Answers  


What is function overloading and operator overloading in C++?

1 Answers   IBS, TCS,


Explain the FOR loop with a help of a code.

1 Answers   Accenture,


What are issues if we mix new and free in C++?

1 Answers  


How does stack look in function calls? When does stack overflow? What can you do to remedy it?

1 Answers   Adobe,


What Is A Default Constructor in C++ ?

1 Answers   Amazon,


Name the operators that cannot be overloaded.

2 Answers   Wipro,


Difference between function overloading and function overriding.

1 Answers   Alter,


Execute the qsort () in c/sort() in c++ library or your own custom sort which will sort any type of data on user defined criteria.

1 Answers   Adobe,


What is the difference between realloc() and free() in C++?

1 Answers   IBS, TCS,


What is a class in C++?

2 Answers   Amazon, TCS, UGC Corporation,


Categories