fork download
  1. #include <iomanip>
  2. #include <iostream>
  3. #include <string>
  4.  
  5. void right_align(const std::string& content, unsigned field_width) {
  6. std::cout << std::quoted(content) << " right aligned in a field of size " << field_width << '\n';
  7. std::cout << "|" << std::right << std::setw(field_width) << content << "|\n\n";
  8. }
  9.  
  10. void left_align(const std::string& content, unsigned field_width) {
  11. std::cout << std::quoted(content) << " left aligned in a field of size " << field_width << '\n';
  12. std::cout << "|" << std::left << std::setw(field_width) << content << "|\n\n";
  13. }
  14.  
  15. int main() {
  16. right_align("*", 20);
  17. left_align("*", 20);
  18.  
  19. std::cout << '\n';
  20.  
  21. right_align("*****", 1);
  22. left_align("*****", 1);
  23. }
Success #stdin #stdout 0s 3472KB
stdin
Standard input is empty
stdout
"*" right aligned in a field of size 20
|                   *|

"*" left aligned in a field of size 20
|*                   |


"*****" right aligned in a field of size 1
|*****|

"*****" left aligned in a field of size 1
|*****|