Create a string from a vector<char>. - C++ STL

C++ examples for STL:string

Description

Create a string from a vector<char>.

Demo Code

#include <iostream>
#include <string>
#include <cctype>
#include <algorithm>
#include <vector>
using namespace std;
int main()/*from ww  w .  ja v a2 s.co m*/
{
   string strA("This is a test. another test test test");

   // Create an iterator to a string.

   string::iterator itr;
   // Create a string from a vector<char>.
   vector<char> vec;
   for(int i=0; i < 10; ++i)
      vec.push_back('A'+i);
   string strC(vec.begin(), vec.end());

   cout << "Here is strC, which is constructed from a vector:\n";

   cout << strC << endl;

   return 0;
}

Result


Related Tutorials