📜  C++中的ios操纵器skipws()函数

📅  最后修改于: 2021-05-30 08:29:30             🧑  作者: Mango

C++中的流操纵器skipws()方法用于为指定的str流设置skipws格式标志。此标志在第一个非空白字符之前跳过输入流中的空白。

句法:

ios_base& skipws (ios_base& str)

参数:此方法接受str作为参数,这是影响格式标志的流。

返回值:该方法返回设置了skipws格式标志的str。

范例1:

// C++ code to demonstrate
// the working of skipws() function
  
#include 
#include 
  
using namespace std;
  
int main()
{
  
    // Initializing the character
    char a, b, c;
  
    // Stream input with leading whitespaces
    istringstream iss("        GFG");
  
    // Using skipws()
    iss >> skipws >> a >> b >> c;
  
    cout << "skipws flag: "
         << a << endl
         << b << endl
         << c << endl;
  
    return 0;
}
输出:
skipws flag: G
F
G

范例2:

// C++ code to demonstrate
// the working of skipws() function
  
#include 
#include 
  
using namespace std;
  
int main()
{
  
    // Initializing the character
    char a;
  
    // Stream input with leading whitespaces
    istringstream iss("        G");
  
    // Using skipws()
    iss >> skipws >> a;
  
    cout << "skipws flag: "
         << a << endl;
  
    return 0;
}
输出:
skipws flag: G

参考: http : //www.cplusplus.com/reference/ios/skipws/

要从最佳影片策划和实践问题去学习,检查了C++基础课程为基础,以先进的C++和C++ STL课程基础加上STL。要完成从学习语言到DS Algo等的更多准备工作,请参阅“完整面试准备课程”