Q:

Write a program that initializes a string from a vector<char>

0

Write a program that initializes a string from a vector<char>.

All Answers

need an explanation for this answer? contact us directly to get an explanation for this answer

#include <vector>
#include <string>
#include <iostream>

int main() {
  std::vector<char> vc{'H', 'e', 'l', 'l', 'o', ' ', 'w', 'o', 'r', 'l', 'd'};
  std::string str(vc.cbegin(), vc.cend());

  std::cout << str << std::endl;

  return 0;
}

need an explanation for this answer? contact us directly to get an explanation for this answer

total answers (1)

Similar questions


need a help?


find thousands of online teachers now