Advertisement
WeltEnSTurm

Console IO

Apr 21st, 2012
361
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.07 KB | None | 0 0
  1.  
  2. #ifndef WS_IO_HPP_
  3. #define WS_IO_HPP_
  4.  
  5. #include <iostream>
  6. #include "base.hpp"
  7. #include "ws/exception.hpp"
  8.  
  9. namespace ws {
  10.     namespace io {
  11.  
  12.         inline void write(){}
  13.  
  14.         template<typename T, typename... Args>
  15.         inline void write(const T& o, Args... args){
  16.             std::cout << o;
  17.             write(args...);
  18.         }
  19.  
  20.         template<typename T, typename... Args>
  21.         inline void write(string s, T value, Args... args) {
  22.             if(s.find('%') < s.size()){
  23.                 long i = s.find('%');
  24.                 write(s.substr(0, i));
  25.                 write(value);
  26.                 write(s.substr(i+1, s.size()-i-1), args...);
  27.             } else {
  28.                 write(s);
  29.                 write(value, args...);
  30.             }
  31.         }
  32.  
  33.         template<typename... Args>
  34.         inline void write(const char c[], Args... args){
  35.             write(string(c), args...);
  36.         }
  37.  
  38.         template<typename... Args>
  39.         inline void writeln(Args... args){
  40.             write(args...);
  41.             std::cout << std::endl;
  42.         }
  43.  
  44.         template<typename T>
  45.         inline void getln(T& t){
  46.             std::getline(std::cin, t);
  47.         }
  48.        
  49.         inline string getln(){
  50.             string line;
  51.             std::getline(std::cin, line);
  52.             return line;
  53.         }
  54.  
  55.     }
  56. }
  57.  
  58. #endif
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement