std::ends
std::ends (null 문자 조작자)
출력 시퀀스 os에 os.put(CharT())를 호출한 것처럼 null 문자를 삽입하는 조작자예요. 출력 전용 I/O 조작자예요.
출처: cppreference
본문
<ostream> 헤더에 정의돼 있어요.
template< class CharT, class Traits >
std::basic_ostream<CharT, Traits>& ends( std::basic_ostream<CharT, Traits>& os );
출력 시퀀스 os에 os.put(CharT())를 호출한 것처럼 null 문자를 삽입해요. 출력 전용 I/O 조작자라 std::basic_ostream 타입의 out에 대해 out << std::ends처럼 쓸 수 있어요.
참고
이 조작자는 보통 std::ostrstream과 함께 쓰여요. 연관 출력 버퍼를 C 문자열로 처리하려면 null로 종료돼야 할 때 유용해요. std::endl과 달리 이 조작자는 flush하지 않아요.
예제
#include <strstream>
#include <iostream>
int main()
{
std::ostrstream oss;
oss << "Hello" << std::ends; // null 종료
const char* p = oss.str();
std::cout << p << '\n'; // "Hello"
oss.freeze(false);
}