当前位置: 首页>>代码示例>>C++>>正文


C++ ostringstream::rdbuf方法代码示例

本文整理汇总了C++中std::ostringstream::rdbuf方法的典型用法代码示例。如果您正苦于以下问题:C++ ostringstream::rdbuf方法的具体用法?C++ ostringstream::rdbuf怎么用?C++ ostringstream::rdbuf使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在std::ostringstream的用法示例。


在下文中一共展示了ostringstream::rdbuf方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1: GIVEN

#include <lab14a.h>
#include <doctest.h>

#include <iostream>
#include <sstream>
#include <string>
#include <vector>

SCENARIO( "treat animals") {
  GIVEN( "an vector of unique_ptr<Animal>" ) {
    auto zoo = make_animals();
    WHEN( "n is 1" ) {
      THEN( "each animal should complain about a shot" ) {
        std::ostringstream actual;
        auto cout_buff = std::cout.rdbuf(); // save pointer to std::cout buffer
        std::cout.rdbuf(actual.rdbuf());     // sub local for cout
        treat_animals(zoo);
        std::cout.rdbuf(cout_buff);          // restore cout

        std::string expected = "meow.\n";
        auto pos = actual.str().find_first_of(expected); 
        REQUIRE_MESSAGE(pos != std::string::npos, "Did not give a Cat a shot");
        
        expected = "arf, arf!\n";
        pos = actual.str().find_first_of(expected); 
        REQUIRE_MESSAGE(pos != std::string::npos, "Did not give a Dog a shot");
        
        expected = "Hoot!\n";
        pos = actual.str().find_first_of(expected); 
        REQUIRE_MESSAGE(pos != std::string::npos, "Did not give a Owl a shot");
        
开发者ID:DaveParillo,项目名称:cisc187,代码行数:30,代码来源:step5.cpp

示例2: defined

#include <unordered_map>
#include <unordered_set>
#include <iostream>

#if defined(_MSC_VER)
    #pragma warning (push)
    #pragma warning (disable : 4189) // local variable is initialized but not referenced
#endif

TEST_CASE("README", "[hide]")
{
    {
        // redirect std::cout for the README file
        auto old_cout_buffer = std::cout.rdbuf();
        std::ostringstream new_stream;
        std::cout.rdbuf(new_stream.rdbuf());
        {
            // create an empty structure (null)
            json j;

            // add a number that is stored as double (note the implicit conversion of j to an object)
            j["pi"] = 3.141;

            // add a Boolean that is stored as bool
            j["happy"] = true;

            // add a string that is stored as std::string
            j["name"] = "Niels";

            // add another null object by passing nullptr
            j["nothing"] = nullptr;
开发者ID:jango2015,项目名称:json,代码行数:31,代码来源:unit-readme.cpp

示例3: out

// Copyright (C) 2016 Jonathan Müller <[email protected]>
// This file is subject to the license terms in the LICENSE file
// found in the top-level directory of this distribution.

#include <standardese/output.hpp>

#include <catch.hpp>

using namespace standardese;

TEST_CASE("output_stream_base")
{
    std::ostringstream str;
    streambuf_output out(*str.rdbuf());

    SECTION("newline test")
    {
        out.write_char('a');
        out.write_new_line();

        out.write_str("b\n", 2);
        out.write_new_line();

        out.write_str("c ignore me", 1);
        out.write_blank_line();

        out.write_str("d\n", 2);
        out.write_blank_line();

        REQUIRE(str.str() == "a\nb\nc\n\nd\n\n");
    }
开发者ID:Manu343726,项目名称:standardese,代码行数:31,代码来源:output.cpp

示例4: Serialize

 Serialize(const void* Buffer, std::size_t BufferSize) : Data()
 {
     Data.rdbuf()->pubsetbuf(const_cast<char*>(reinterpret_cast<const char*>(Buffer)), BufferSize);
 }
开发者ID:Brandon-T,项目名称:GLX,代码行数:4,代码来源:Serialization.hpp

示例5: ExpectedStreamOutput

 ExpectedStreamOutput(std::ostream &stream,const char *expected_)
     : expected(expected_), original_stream(stream), original_streambuf(*(stream.rdbuf(substituted_stream.rdbuf())))
 {
 }
开发者ID:HanumathRao,项目名称:stack_unwinding,代码行数:4,代码来源:examples_common.hpp

示例6: Hello

 * Sources     :
 */
#define CATCH_CONFIG_MAIN
#include "catch.hpp"

#include <sstream>
#include <iostream>
#include <string>
#include "lab_5.h"
using std::string;

TEST_CASE("Hello Function") {
  string cout_output;
  std::streambuf* oldCout = cout.rdbuf();
  std::ostringstream captureCout;
  cout.rdbuf(captureCout.rdbuf());
  Hello();
  cout.rdbuf(oldCout);
  cout_output = captureCout.str();
  SECTION("Hello()") {
    CHECK(cout_output == "Hello world!");
  }
  captureCout.str("");
}

TEST_CASE("Print Message Function") {
  string cout_output;
  std::streambuf* oldCout = cout.rdbuf();
  std::ostringstream captureCout;
  cout.rdbuf(captureCout.rdbuf());
  PrintMessage("Hello again!");
开发者ID:agonzales004,项目名称:CSCI-21-SPRING-2016,代码行数:31,代码来源:lab_5_unit_test.cpp


注:本文中的std::ostringstream::rdbuf方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。