Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <string>
- #include <algorithm>
- #define CONSOLE_CHAR_WIDTH 80
- std::string& center_str(std::string& str, const char ch = ' ')
- {
- std::string tmpstr(str);
- str.clear();
- str.resize(CONSOLE_CHAR_WIDTH);
- std::fill(str.begin(), str.end(), ch);
- str.replace((CONSOLE_CHAR_WIDTH - tmpstr.length()) / 2, tmpstr.length(), tmpstr);
- std::fill(str.begin() + (CONSOLE_CHAR_WIDTH / 2) + tmpstr.length(), str.end(), ch);
- return str;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement