How to use append() function In C++
Create a string and append characters one by one into that string by traversing into the container.
Syntax:
string_name.append(1, character);
Example:
C++
// C++ program to convert vector of chars // into string Using append() function #include <bits/stdc++.h> using namespace std; int main() { vector< char > v = { 'A' , 'B' , 'C' , 'D' , 'E' }; string s; for ( char & c : v) { s.append(1, c); s.append(1, ' ' ); } cout << s; return 0; } |
Output
A B C D E
Convert Vector of chars to String in C++
Prerequisites:
Here, we will discuss how to convert the vector of chars to std::string in C++. There are mainly 7 ways to convert Char Vector to String in C++ as follows:
- Using string constructor
- Using String Stream and iterator
- Using String Stream and index
- Using push_back() function
- Using append() function
- Using insert() function
- Using copy() method