How to convert a single character to a string object.
Input : x = 'a' Output : string s = "a" Input : x = 'b' Output : string s = "b"
The idea is to use string class which has a constructor that allows us to specify size of
string as first parameter and character to be filled in given size as second parameter.
// Create a string of size n and fill // the string with character x. string s(int n, char x);
Rated as one of the most sought after skills in the industry, own the basics of coding with our C++ STL Course and master the very concepts by intense problem-solving.
- Convert character array to string in C++
- Check input character is alphabet, digit or special character
- Find the character in first string that is present at minimum index in second string
- OpenCV C++ Program to create a single colored blank image
- Implementing Iterator pattern of a single Linked List
- How to execute zombie and orphan process in a single program?
- Difference between Single and Multiple Inheritance in C++
- Character replacement after removing duplicates from a string
- Program to count occurrence of a given character in a string
- Frequency of each character in a String using unordered_map in C++
- Convert a floating point number to string in C
- How to convert C style strings to std::string and vice versa?
- C++ Program to Convert String to Integer
- Minimum cost to convert given string to consist of only vowels
- Convert string to char array in C++
- Change/add only one character and print '*' exactly 20 times
- Data type of character constants in C and C++
- Type difference of character literals in C and C++
- Character Classification in C++ : cctype
- Character arithmetic in C and C++
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to firstname.lastname@example.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.