首页
学习
活动
专区
工具
TVP
发布
精选内容/技术社群/优惠产品,尽在小程序
立即前往

std::ws

Defined in header <istream>

?

?

template< class CharT, class Traits > std::basic_istream<CharT,Traits>& ws( std::basic_istream<CharT, Traits>& is );

?

?

从输入流中丢弃前导空格。

表现为UnformattedInputFunction,除了is.gcount()没有修改。在构造和检查哨兵对象之后,从流中提取字符并丢弃它们,直到出现下列任何一种情况:

  • 文件结束条件发生在输入序列%28中,在这种情况下,函数调用setstate(eofbit)但没有failbit...
  • 下一个可用字符c在输入序列中不是由std::isspace(c, is.getloc())未提取非空白字符。

这是一个只输入的I/O操作程序,可以用如下表达式调用它in >> std::ws对任何in类型std::basic_istream...

参数

is

-

reference to input stream

返回值

is%28提取连续空格%29后对流的引用。

二次

代码语言:javascript
复制
#include <iostream>
#include <istream>
#include <sstream>
 
int main()
{
    std::istringstream s("     this is a test");
    std::string line;
    getline(s >> std::ws, line);
    std::cout << "ws + getline returns: \"" << line << "\"\n";
}

二次

产出:

二次

代码语言:javascript
复制
ws + getline returns: "this is a test"

二次

另见

ignore

extracts and discards characters until the given character is found (public member function of std::basic_istream)

代码语言:txt
复制
 ? cppreference.com

在CreativeCommonsAttribution下授权-ShareAlike未移植许可v3.0。

扫码关注腾讯云开发者

领取腾讯云代金券

http://www.vxiaotou.com