C, w_wrap.c w_wrap.h, Fidonet C_ECHO 20 .
++, , :
#include <sstream>
#include <string>
#include <iostream>
void wrap(std::string const &input, size_t width, std::ostream &os, size_t indent = 0)
{
std::istringstream in(input);
os << std::string(indent, ' ');
size_t current = indent;
std::string word;
while (in >> word) {
if (current + word.size() > width) {
os << "\n" << std::string(indent, ' ');
current = indent;
}
os << word << ' ';
current += word.size() + 1;
}
}
#ifdef TEST
int main() {
char *in = "Shankle drumstick corned beef, chuck turkey chicken pork chop"
" venison beef strip steak cow sausage. Tail short loin shoulder"
" ball tip, jowl drumstick rump. Tail tongue ball tip meatloaf,"
" bresaola short loin tri-tip fatback pork loin sirloin shank"
" flank biltong. Venison short loin andouille.";
wrap(in, 60, std::cout);
return 0;
}
#endif
, - :
wrap(in, 60, std::cout, 5);
, I/O, , , , , . , , , , . , , - 3 , , () 60 . , - C, .