Mega Code Archive

 
Categories / C++ Tutorial / String
 

Create a string from a vectorchar

#include <iostream> #include <string> #include <cctype> #include <algorithm> #include <vector> using namespace std; int main() {   string strA("This is a test.");   // 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; }