| 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(const char* s, streamsize n); |
| 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 |
const char buf[] = "123 4.5 dog"; |
| 27 |
std::istrstream in(buf, 7); |
| 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 == ""); |
| 37 |
assert(in.eof()); |
| 38 |
assert(in.fail()); |
| 39 |
in.clear(); |
| 40 |
in.putback('5'); |
| 41 |
assert(!in.fail()); |
| 42 |
in.putback('5'); |
| 43 |
assert(in.fail()); |
| 44 |
assert(buf[5] == '.'); |
| 45 |
assert(buf[6] == '5'); |
| 46 |
} |
| 47 |
|
| 48 |
return 0; |
| 49 |
} |