to_string.cpp 1.1 KB

12345678910111213141516171819202122232425262728293031323334353637
  1. #if 0
  2. g++ -Wall -std=c++03 -I/usr/local/include/tr1_fwd -o "$0.run" "$0"
  3. exit
  4. #endif
  5. /*
  6. * cxxomfort example: to_string
  7. *
  8. * This program provides sample usage of the
  9. * "to_string" backport feature.
  10. *
  11. */
  12. #include <cxxomfort/base.hpp>
  13. #include <cxxomfort/cstdio.hpp>
  14. #include <cxxomfort/string.hpp>
  15. #include <string>
  16. #include <iostream>
  17. #include <cstdlib>
  18. int main () {
  19. using namespace std;
  20. cxxomfort::output_info(); cout<< endl;
  21. cout<< "Next line should print '15' as we call to_string(int): "<< endl;
  22. cout<< to_string(15)<< endl;
  23. cout<< "Next line should print '0' as there is no to_string(bool): "<< endl;
  24. cout<< to_string(false)<< endl;
  25. cout<< "Next we invoke to_string for an int, a short and a long: "<< endl;
  26. cout<< to_string(int(1))<< " "<< to_string(short(-1))<< " "<< to_string(long(-2))<< endl;
  27. cout<< "Next line should print something like '15.152000' as we call to_string(floating_point): "<< endl;
  28. cout<< to_string(15.152)<< endl;
  29. cout<< "Next line should print '63', the dec value of 0x3f, as we can't pass 'hex <<' to the formatting: "<< endl;
  30. cout<< to_string(0x3f)<< endl;
  31. return 0;
  32. }