Movatterモバイル変換


[0]ホーム

URL:


cppreference.com
Namespaces
Variants
    Actions

      std::strstreambuf::strstreambuf

      From cppreference.com
      <cpp‎ |io‎ |strstreambuf
       
       
       
       
      (1)
      explicit strstreambuf(std::streamsize alsize=0);
      (deprecated in C++98)
      (until C++11)
      strstreambuf(): strstreambuf(0){}
      explicit strstreambuf(std::streamsize alsize);
      (since C++11)(removed in C++26)
      strstreambuf(void*(*palloc)(std::size_t),void(*pfree)(void*));
      (2)(deprecated in C++98)
      (removed in C++26)
      strstreambuf(char* gnext,std::streamsize n,char* pbeg=0);
      (3)(deprecated in C++98)
      (removed in C++26)
      strstreambuf(signedchar* gnext,std::streamsize n,signedchar* pbeg=0);
      (4)(deprecated in C++98)
      (removed in C++26)
      strstreambuf(unsignedchar* gnext,std::streamsize n,unsignedchar* pbeg=0);
      (5)(deprecated in C++98)
      (removed in C++26)
      strstreambuf(constchar* gnext,std::streamsize n);
      (6)(deprecated in C++98)
      (removed in C++26)
      strstreambuf(constsignedchar* gnext,std::streamsize n);
      (7)(deprecated in C++98)
      (removed in C++26)
      strstreambuf(constunsignedchar* gnext,std::streamsize n);
      (8)(deprecated in C++98)
      (removed in C++26)
      1) Constructs astd::strstreambuf object: initializes the base class by calling the default constructor ofstd::streambuf, initializes the buffer state to "dynamic" (the buffer will be allocated as needed), initializes allocated size to the providedalsize, initializes the allocation and the deallocation functions to null (will usenew[] anddelete[]).
      2) Constructs astd::strstreambuf object: initializes the base class by calling the default constructor ofstd::streambuf, initializes the buffer state to "dynamic" (the buffer will be allocated as needed), initializes allocated size to unspecified value, initializes the allocation function topalloc and the deallocation function topfree.
      3-5) Constructs astd::strstreambuf object in following steps:
      a) Initializes the base class by calling the default constructor ofstd::streambuf.
      b) Initializes the buffer state to "constant" (the buffer is a user-provided fixed-size buffer).
      c) Determines the number of elements in the user-provided array as follows: ifn is greater than zero,n is used. Ifn is zero,std::strlen(gnext) is executed to determine the buffer size. Ifn is negative,INT_MAX is used.
      d) Configures thestd::basic_streambuf pointers as follows: Ifpbeg is a null pointer, callssetg(gnext, gnext, gnext+ N). Ifpbeg is not a null pointer, executessetg(gnext, gnext, pbeg) andsetp(pbeg, pbeg+ N), where N is the number of elements in the array as determined earlier.
      6-8) Same asstrstreambuf((char*)gnext, n), except the "constant" bit is set in the buffer state bitmask (output to this buffer is not allowed).

      Contents

      [edit]Parameters

      alsize - the initial size of the dynamically allocated buffer
      palloc - pointer to user-provided allocation function
      pfree - pointer to user-provided deallocation function
      gnext - pointer to the start of the get area in the user-provided array
      pbeg - pointer to the start of the put area in the user-provided array
      n - the number of bytes in the get area (if pbeg is null) or in the put area (if pbeg is not null) of the user-provided array

      [edit]Notes

      These constructors are typically called by the constructors ofstd::strstream.

      [edit]Defect reports

      The following behavior-changing defect reports were applied retroactively to previously published C++ standards.

      DRApplied toBehavior as publishedCorrect behavior
      P0935R0C++11default constructor was explicitmade implicit

      [edit]Example

      Run this code
      #include <iostream>#include <strstream> int main(){std::strstreambuf dyn;// dynamicstd::strstream dyn_s;// equivalent stream    dyn_s<<1.23<<std::ends;std::cout<< dyn_s.str()<<'\n';    dyn_s.freeze(false); char buf[10];std::strstreambuf user(buf,10, buf);// user-provided output bufferstd::ostrstream user_s(buf,10);// equivalent stream    user_s<<1.23<<std::ends;std::cout<< buf<<'\n'; std::strstreambuf lit("1 2 3",5);// constantstd::istrstream lit_s("1 2 3");// equivalent streamint i, j, k;    lit_s>> i>> j>> k;std::cout<< i<<' '<< j<<' '<< k<<'\n';}

      Output:

      1.231.231 2 3

      [edit]See also

      constructs astrstream object, optionally allocating the buffer
      (public member function ofstd::strstream)[edit]
      Retrieved from "https://en.cppreference.com/mwiki/index.php?title=cpp/io/strstreambuf/strstreambuf&oldid=170644"

      [8]ページ先頭

      ©2009-2025 Movatter.jp