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); 15 16 #include <strstream> 17 #include <cassert> 18 #include <string> 19 main()20int main() 21 { 22 { 23 char buf[] = "123 4.5 dog"; 24 std::istrstream in(buf); 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 == "dog"); 34 assert(in.eof()); 35 assert(!in.fail()); 36 in.clear(); 37 in.putback('g'); 38 assert(!in.fail()); 39 in.putback('g'); 40 assert(!in.fail()); 41 assert(buf[9] == 'g'); 42 assert(buf[10] == 'g'); 43 } 44 } 45