fork(1) download
  1. #include <iostream>
  2. #include <string>
  3.  
  4. const uint STRING_LENGTH = 25;
  5.  
  6. std::string&& fix_length(std::string &&s) {
  7. s.resize(STRING_LENGTH, ' ');
  8. return std::move(s);
  9. }
  10.  
  11. struct parameter {
  12. double value;
  13. std::string name;
  14.  
  15. parameter(double _value, std::string _name)
  16. : value(_value), name(fix_length(std::move(_name)))
  17. {
  18. }
  19. };
  20.  
  21.  
  22. int main() {
  23. parameter A(0.5, "my_variable");
  24. parameter B(-0.1, "my other variable with the name that is too long and has to be truncated!");
  25.  
  26. std::cout << "parameter name: " << A.name << "\tis:\t" << A.value << '\n';
  27. std::cout << "parameter name: " << B.name << "\tis:\t" << B.value << '\n';
  28. }
Success #stdin #stdout 0.01s 5508KB
stdin
Standard input is empty
stdout
parameter name: my_variable              	is:	0.5
parameter name: my other variable with th	is:	-0.1