| 1 | //===----------------------------------------------------------------------===// |
| 2 | // |
| 3 | // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. |
| 4 | // See https://llvm.org/LICENSE.txt for license information. |
| 5 | // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception |
| 6 | // |
| 7 | //===----------------------------------------------------------------------===// |
| 8 | |
| 9 | // ADDITIONAL_COMPILE_FLAGS: -D_LIBCPP_DISABLE_DEPRECATION_WARNINGS -D_LIBCPP_ENABLE_CXX26_REMOVED_STRSTREAM |
| 10 | |
| 11 | // <strstream> |
| 12 | |
| 13 | // class istrstream |
| 14 | |
| 15 | // explicit istrstream(char* s); |
| 16 | |
| 17 | #include <strstream> |
| 18 | #include <cassert> |
| 19 | #include <string> |
| 20 | |
| 21 | #include "test_macros.h" |
| 22 | |
| 23 | int main(int, char**) |
| 24 | { |
| 25 | { |
| 26 | char buf[] = "123 4.5 dog" ; |
| 27 | std::istrstream in(buf); |
| 28 | int i; |
| 29 | in >> i; |
| 30 | assert(i == 123); |
| 31 | double d; |
| 32 | in >> d; |
| 33 | assert(d == 4.5); |
| 34 | std::string s; |
| 35 | in >> s; |
| 36 | assert(s == "dog" ); |
| 37 | assert(in.eof()); |
| 38 | assert(!in.fail()); |
| 39 | in.clear(); |
| 40 | in.putback(c: 'g'); |
| 41 | assert(!in.fail()); |
| 42 | in.putback(c: 'g'); |
| 43 | assert(!in.fail()); |
| 44 | assert(buf[9] == 'g'); |
| 45 | assert(buf[10] == 'g'); |
| 46 | } |
| 47 | |
| 48 | return 0; |
| 49 | } |
| 50 | |