65 lines · cpp
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-exception6//7//===----------------------------------------------------------------------===//8 9// <sstream>10 11// template <class charT, class traits = char_traits<charT>, class Allocator = allocator<charT> >12// class basic_stringstream13 14// template <class charT, class traits, class Allocator>15// void16// swap(basic_stringstream<charT, traits, Allocator>& x,17// basic_stringstream<charT, traits, Allocator>& y);18 19#include <sstream>20#include <cassert>21 22#include "test_macros.h"23 24int main(int, char**)25{26 {27 std::stringstream ss0(" 123 456 ");28 std::stringstream ss;29 swap(ss, ss0);30 assert(ss.rdbuf() != 0);31 assert(ss.good());32 assert(ss.str() == " 123 456 ");33 int i = 0;34 ss >> i;35 assert(i == 123);36 ss >> i;37 assert(i == 456);38 ss << i << ' ' << 123;39 assert(ss.str() == "456 1236 ");40 ss0 << i << ' ' << 123;41 assert(ss0.str() == "456 123");42 }43#ifndef TEST_HAS_NO_WIDE_CHARACTERS44 {45 std::wstringstream ss0(L" 123 456 ");46 std::wstringstream ss;47 swap(ss, ss0);48 assert(ss.rdbuf() != 0);49 assert(ss.good());50 assert(ss.str() == L" 123 456 ");51 int i = 0;52 ss >> i;53 assert(i == 123);54 ss >> i;55 assert(i == 456);56 ss << i << ' ' << 123;57 assert(ss.str() == L"456 1236 ");58 ss0 << i << ' ' << 123;59 assert(ss0.str() == L"456 123");60 }61#endif62 63 return 0;64}65