- Data Structure
- Networking
- RDBMS
- Operating System
- Java
- MS Excel
- iOS
- HTML
- CSS
- Android
- Python
- C Programming
- C++
- C#
- MongoDB
- MySQL
- Javascript
- PHP
- Physics
- Chemistry
- Biology
- Mathematics
- English
- Economics
- Psychology
- Social Studies
- Fashion Studies
- Legal Studies
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
How to convert an int to string in C++?
You can use the itoa function from C to convert an int to string.
example
#include<iostream> int main() { int a = 10; char *intStr = itoa(a); string str = string(intStr); cout << str; }
Output
This will give the output −
10
This will convert the integer to a string. In C++11, a new method, to_string was added that can be used for the same purpose. You can use it as follows −
Example
#include<iostream> using namespace std; int main() { int a = 10; string str = to_string(a); cout << str; }
Output
This will give the output −
10
Advertisements