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

int main()
{
	std::string str = "I need to split input string";   
	std::vector<std::string> output;
	
	std::istringstream iss(str);
	std::string word;
    const int max = 10;

	while((iss >> word))
    {	
	    // Check if the last element can still hold another word (+ space)
	    if (output.size() > 0 && (output[output.size() - 1].size() + word.size() + 1) <= max)
	        output[output.size() - 1] += ' ' + word;
	    else        
	        output.push_back(word);
	}
	
	for (auto&it : output)
	    std::cout << it << std::endl;
    
	return 0;
}