How to convert a string to vector of chars in C++

2 Answers

0 votes
#include <iostream>
#include <vector>
 
using namespace std;

int main() {
    string s = "c c++ java php";

    vector<char> vec(s.begin(), s.end());
    
    for (char val : vec)
        cout << val;
}
 
 
 
 
/*
run:
 
c c++ java php
 
*/

 



answered Jul 11, 2019 by avibootz
0 votes
#include <iostream>
#include <vector>
 
using namespace std;

int main() {
    string s = "c c++ java php";
    
    vector<char> vec;
    
	copy(s.begin(), s.end(), back_inserter(vec));

	for (char ch : vec)
        cout << ch;
}
 
 
 
 
/*
run:
 
c c++ java php
 
*/

 



answered Jul 11, 2019 by avibootz
...