Namespaces
Variants

std::basic_streambuf<CharT,Traits>:: sputn, std::basic_streambuf<CharT,Traits>:: xsputn

From cppreference.net
std:: streamsize sputn ( const char_type * s, std:: streamsize count ) ;
(1)
protected :
virtual std:: streamsize xsputn ( const char_type * s, std:: streamsize count ) ;
(2)
1) 가장 파생된 클래스의 xsputn ( s, count ) 를 호출합니다.
2) s 가 가리키는 첫 번째 요소부터 시작하는 문자 배열에서 출력 시퀀스로 count 개의 문자를 씁니다. 문자들은 sputc() 를 반복적으로 호출하는 것처럼 기록됩니다. count 개의 문자가 기록되거나 sputc() 호출이 Traits :: eof ( ) 를 반환할 경우 기록이 중단됩니다.

만약 put 영역이 가득 차면 ( pptr ( ) == epptr ( ) ), overflow() 가 실제로 호출되는지 또는 그 효과가 다른 방법으로 달성되는지는 명시되지 않습니다.

목차

매개변수

(없음)

반환값

성공적으로 기록된 문자 수.

참고 사항

"다른 수단으로 달성됨"은 중간 버퍼링 없이 대량 I/O를 허용합니다: 이것이 일부 구현에서 std::ofstream::write() 가 단순히 포인터를 적절한 시스템 호출에 전달하는 방식입니다.

예제

#include <iostream>
#include <sstream>
int main()
{
    std::ostringstream s1;
    std::streamsize sz = s1.rdbuf()->sputn("This is a test", 14);
    s1 << '\n';
    std::cout << "The call to sputn() returned " << sz << '\n'
              << "The output sequence contains " << s1.str();
    std::istringstream s2;
    sz = s2.rdbuf()->sputn("This is a test", 14);
    std::cout << "The call to sputn() on an input stream returned " << sz << '\n';
}

출력:

The call to sputn() returned 14
The output sequence contains This is a test
The call to sputn() on an input stream returned 0

결함 보고서

다음의 동작 변경 결함 보고서들은 이전에 발표된 C++ 표준에 소급 적용되었습니다.

DR 적용 대상 게시된 동작 올바른 동작
LWG 565 C++98 xsputn() 가 항상 overflow() 를 호출함 pptr ( ) == epptr ( ) 인 경우 실제로 호출될 필요가 없음

참고 항목

xsgetn ( ) 를 호출합니다
(public member function)