fork(2) download
  1. #include <iostream>
  2. #include <vector>
  3. #include <streambuf>
  4. using namespace std;
  5.  
  6. // http://stackoverflow.com/questions/8815164/c-wrapping-vectorchar-with-istream
  7. template<typename CharT, typename TraitsT = std::char_traits<CharT> >
  8. class vectorwrapbuf : public std::basic_streambuf<CharT, TraitsT>
  9. {
  10. public:
  11. vectorwrapbuf(std::vector<CharT> &vec)
  12. {
  13. this->setg(&vec[0], &vec[0], &vec[0] + vec.size());
  14. }
  15. };
  16.  
  17. int main()
  18. {
  19. vector<char> data(100, 1);
  20. vectorwrapbuf<char> databuf(data);
  21. std::istream file(&databuf);
  22. file.exceptions(std::istream::failbit | std::istream::badbit);
  23. file.seekg(10);
  24. }
  25.  
Runtime error #stdin #stdout #stderr 0s 3456KB
stdin
Standard input is empty
stdout
Standard output is empty
stderr
terminate called after throwing an instance of 'std::ios_base::failure'
  what():  basic_ios::clear