convert string into vector c++ code example
Example 1: string to vector c++
#include <iostream>
#include <string>
#include <vector>
int main()
{
std::string s = "Hello World!";
std::vector<char> v(s.begin(), s.end());
for (const char &c: v)
std::cout << c;
return 0;
}
Example 2: c++ string to vector int
#include <sstream>
#include <vector>
#include <string>
std::string myString = "10 15 20 23";
std::stringstream iss( myString );
int number;
std::vector<int> myNumbers;
while ( iss >> number )
myNumbers.push_back( number );