// The string we will be working with
std::string str = "Hello, World!";
// The vector we want to store the string in (2 characters per element)
std::vector < std::string > vec;
// Here we store characters until its length == 2, then we add it to vec
std::string temp;
// Loop through all the characters of str
for ( int i = 0; i < str.length(); ++i )
{
// Add the current character to temp
temp += str[ i ];
// If temp's length is equal to 2 (or bigger, but that won't happen)
if ( temp.length() >= 2 )
{
// Add temp to the vector
vec.push_back( temp );
// Reset temp
temp = "";
}
}
// If the length of str was an odd number, we still have a character left in
// temp, so add that to vec too
if ( temp.length() != 0 )
{
vec.push_back( temp );
}