📜  带有示例的C++中的ios运算符()函数

📅  最后修改于: 2021-05-30 13:14:21             🧑  作者: Mango

C++中ios类运算符()方法用于设置此流的任何错误标志。这包括故障位或故障位。

句法:

operator void*() const;

参数:此方法不接受任何参数。

返回值:如果此流的任何错误位被设置,则此方法返回空指针。

范例1:

// C++ code to demonstrate
// the working of operator() function
  
#include 
using namespace std;
  
int main()
{
  
    // Stream
    stringstream ss;
  
    // Using operator() function
    if (ss) {
        cout << "No error bit is set.\n";
    }
    else {
        cout << "Error bit is set.\n";
    }
  
    return 0;
}
输出:
No error bit is set.

范例2:

// C++ code to demonstrate
// the working of operator() function
  
#include 
using namespace std;
  
int main()
{
  
    // Stream
    stringstream ss;
    ss.clear(ss.failbit);
  
    // Using operator() function
    if (ss) {
        cout << "No error bit is set.\n";
    }
    else {
        cout << "Error bit is set.\n";
    }
  
    return 0;
}
输出:
Error bit is set.

参考: hhttp://www.cplusplus.com/reference/ios/ios/运算符/

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