Movatterモバイル変換


[0]ホーム

URL:


cppreference.com
Namespaces
Variants
    Actions

      std::istrstream::istrstream

      From cppreference.com
      <cpp‎ |io‎ |istrstream
       
       
       
       
      explicit istrstream(constchar* s);
      (1)(deprecated in C++98)
      (removed in C++26)
      explicit istrstream(char* s);
      (2)(deprecated in C++98)
      (removed in C++26)
      istrstream(constchar* s,std::streamsize n);
      (3)(deprecated in C++98)
      (removed in C++26)
      istrstream(char* s,std::streamsize n);
      (4)(deprecated in C++98)
      (removed in C++26)

      Constructs newstd::istrstream and its underlyingstd::strstreambuf.

      1,2) Constructs the underlyingstd::strstreambuf by callingstrstreambuf(s,0) and initializes the base class with the address of thestrstreambuf. The behavior is undefined ifs is not pointing at an element of a null-terminated array.
      3,4) Constructs the underlyingstd::strstreambuf by callingstrstreambuf(s, n) and initializes the base class with the address of thestrstreambuf. The behavior is undefined ifs is not pointing at an element of an array whose length is at leastn elements.

      [edit]Parameters

      s - C-string or char array to use as the contents of the stream
      n - size of the array

      [edit]Example

      Run this code
      #include <iostream>#include <strstream> int main(){std::istrstream s1("1 2 3");// string literalint n1, n2, n3;if(s1>> n1>> n2>> n3)std::cout<< n1<<", "<< n2<<", "<< n3<<'\n'; char arr[]={'4',' ','5',' ','6'};std::istrstream s2(arr, sizeof arr);if(s2>> n1>> n2>> n3)std::cout<< n1<<", "<< n2<<", "<< n3<<'\n';}

      Output:

      1, 2, 34, 5, 6

      [edit]See also

      constructs astrstreambuf object
      (public member function ofstd::strstreambuf)[edit]
      constructs anostrstream object, optionally allocating the buffer
      (public member function ofstd::ostrstream)[edit]
      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/istrstream/istrstream&oldid=170636"

      [8]ページ先頭

      ©2009-2026 Movatter.jp