Namespaces
Variants

std::basic_streambuf<CharT,Traits>:: sgetc

From cppreference.net
int_type sgetc ( ) ;

从输入序列中读取一个字符。

如果输入序列读取位置不可用,则返回 underflow() 。否则返回 Traits :: to_int_type ( * gptr ( ) )

目录

参数

(无)

返回值

get pointer 指向的字符值。

示例

#include <iostream>
#include <sstream>
int main()
{
    std::stringstream stream("Hello, world");
    std::cout << "sgetc() returned '" << (char)stream.rdbuf()->sgetc() << "'\n";
    std::cout << "peek() returned '" << (char)stream.peek() << "'\n";
    std::cout << "get() returned '" << (char)stream.get() << "'\n";
}

输出:

sgetc() returned 'H'
peek() returned 'H'
get() returned 'H'

参见

(C++17 中移除)
从输入序列读取一个字符并前移序列
(公开成员函数)
前移输入序列,然后读取一个字符且不再前移
(公开成员函数)