Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- $ myprog < inputfile.dat > output.txt 2> errors.txt
- $ cat test.cc
- #include <exception>
- #include <stdarg.h>
- #include <stdio.h>
- struct exception_fmt : std::exception
- {
- exception_fmt(char const* fmt, ...) __attribute__ ((format(printf,2,3)));
- char const* what() const throw() { return msg_; }
- char msg_[0x800];
- };
- exception_fmt::exception_fmt(char const* fmt, ...)
- {
- va_list ap;
- va_start(ap, fmt);
- vsnprintf(msg_, sizeof msg_, fmt, ap);
- va_end(ap);
- }
- int main(int ac, char** av)
- {
- throw exception_fmt("%s: bad number of arguments %d", *av, ac);
- }
- $ g++ -Wall -o test test.cc
- $ ./test
- terminate called after throwing an instance of 'exception_fmt'
- what(): ./test: bad number of arguments 1
- Aborted (core dumped)
- #include <stdio.h>
- int sprintf (char *string, const char *format
- [,item [,item]…]);
- printf format [argument]…
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement