
- C++ Basics
- C++ Home
- C++ Overview
- C++ Environment Setup
- C++ Basic Syntax
- C++ Comments
- C++ Data Types
- C++ Variable Types
- C++ Variable Scope
- C++ Constants/Literals
- C++ Modifier Types
- C++ Storage Classes
- C++ Operators
- C++ Loop Types
- C++ Decision Making
- C++ Functions
- C++ Numbers
- C++ Arrays
- C++ Strings
- C++ Pointers
- C++ References
- C++ Date & Time
- C++ Basic Input/Output
- C++ Data Structures
- C++ Object Oriented
- C++ Classes & Objects
- C++ Inheritance
- C++ Overloading
- C++ Polymorphism
- C++ Abstraction
- C++ Encapsulation
- C++ Interfaces
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
- Related Articles
- How to convert a String to an int in Java
- How to convert a Java String to an Int?
- How to convert int to String in java?
- How to convert int to string in Python?
- Java Program to convert an int value to String
- How to convert Int to Hex String in Kotlin?
- Convert int to String in Java
- Convert String to Java int
- How to convert a string to int in Lua programming?
- How to convert hex string into int in Python?
- How to convert a String into int in Java?
- How to convert a string into int in C#?
- MongoDB query to convert string to int?
- Java Program to convert a String to int
- Java Program to convert int to binary string

Advertisements