1 //===----------------------------------------------------------------------===// 2 // 3 // The LLVM Compiler Infrastructure 4 // 5 // This file is dual licensed under the MIT and the University of Illinois Open 6 // Source Licenses. See LICENSE.TXT for details. 7 // 8 //===----------------------------------------------------------------------===// 9 10 // <strstream> 11 12 // class istrstream 13 14 // explicit istrstream(char* s, streamsize n); 15 16 #include <strstream> 17 #include <cassert> 18 #include <string> 19 20 int main() 21 { 22 { 23 char buf[] = "123 4.5 dog"; 24 std::istrstream in(buf, 7); 25 int i; 26 in >> i; 27 assert(i == 123); 28 double d; 29 in >> d; 30 assert(d == 4.5); 31 std::string s; 32 in >> s; 33 assert(s == ""); 34 assert(in.eof()); 35 assert(in.fail()); 36 in.clear(); 37 in.putback('5'); 38 assert(!in.fail()); 39 in.putback('5'); 40 assert(!in.fail()); 41 assert(buf[5] == '5'); 42 assert(buf[6] == '5'); 43 } 44 } 45