Vector <char> to segment segmentation error
trying to initialize a string from a vector. I have to get "hey" as a result. but I got a "segmentation fault". What have I done wrong?
//write a program that initializes a string from a vector<char> #include <iostream> #include <vector> #include <string> using namespace std; int main () { vector<char> cvec; cvec[0]='h'; cvec[1]='e'; cvec[2]='y'; string s(cvec.begin(),cvec.end()); cout<<s<<endl; return 0; } +6
2 answers