C++ Istream 库 - ws



描述

它用于从输入序列中的当前位置提取尽可能多的空白字符。一旦找到非空白字符,提取就会停止。这些提取的空白字符将被丢弃。

声明

以下是 std::ws 的声明。

for istream	    istream& ws (istream& is);
basic template	template <class charT, class traits>
                basic_istream<charT,traits>& ws (basic_istream<charT,traits>& is);

参数

is − 提取空白字符的输入流对象。

异常

基本保证 − 如果抛出异常,流将处于有效状态。

数据竞争

修改流对象 is。

示例

以下示例说明了 std::ws 的用法。

#include <iostream>
#include <sstream>

int main () {
   char a[10], b[10];

   std::istringstream iss ("one \n \t two");
   iss >> std::noskipws;
   iss >> a >> std::ws >> b;
   std::cout << a << ", " << b << '\n';

   return 0;
}

让我们编译并运行上述程序,这将产生以下结果:

one, two
istream.htm
广告

© . All rights reserved.