Advertisement
Guest User

Untitled

a guest
Oct 31st, 2014
173
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.86 KB | None | 0 0
  1. $ myprog < inputfile.dat > output.txt 2> errors.txt
  2.  
  3. $ cat test.cc
  4. #include <exception>
  5. #include <stdarg.h>
  6. #include <stdio.h>
  7.  
  8. struct exception_fmt : std::exception
  9. {
  10. exception_fmt(char const* fmt, ...) __attribute__ ((format(printf,2,3)));
  11. char const* what() const throw() { return msg_; }
  12. char msg_[0x800];
  13. };
  14.  
  15. exception_fmt::exception_fmt(char const* fmt, ...)
  16. {
  17. va_list ap;
  18. va_start(ap, fmt);
  19. vsnprintf(msg_, sizeof msg_, fmt, ap);
  20. va_end(ap);
  21. }
  22.  
  23. int main(int ac, char** av)
  24. {
  25. throw exception_fmt("%s: bad number of arguments %d", *av, ac);
  26. }
  27.  
  28. $ g++ -Wall -o test test.cc
  29.  
  30. $ ./test
  31. terminate called after throwing an instance of 'exception_fmt'
  32. what(): ./test: bad number of arguments 1
  33. Aborted (core dumped)
  34.  
  35. #include <stdio.h>
  36. int sprintf (char *string, const char *format
  37. [,item [,item]…]);
  38.  
  39. printf format [argument]…
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement