#include <iostream>

std::string fmt(size_t margin, size_t width, std::string text)
{
	std::string result;
	while (!text.empty())
	{
		result += std::string(margin, ' ');
		if (width >= text.size())
		    return (result += text) += '\n';
		size_t n = width - 1;
		while (n > width / 2 && isalnum(text[n]) && isalnum(text[n - 1]))
		    --n; // between characters - reduce width until word break or 1/2 width left
		(result += text.substr(0, n)) += '\n';
		text.erase(0, n);
	}
	return result;
}

int main()
{
	std::cout << fmt(5, 70,
	    "This is essentially what I do with large blocks of "
        "descriptive text. It lets me see how long each of "
        "the lines will be, but it's really a hassle, see?"); 

}