c++问题,ios::fail怎么用?
问题是这样的,创建复数类,重载流提取和插入运算符为友元函数,流提取运算符判断输入的数据是否合法,如果非法则置位ios::fail以知识输入不正确,需按以下格式输入3+8i...
问题是这样的,创建复数类,重载流提取和插入运算符为友元函数,流提取运算符判断输入的数据是否合法,如果非法则置位ios::fail以知识输入不正确,需按以下格式输入3+8i,编写main函数测试输入输出
展开
1个回答
展开全部
bool fail( ) const;
Return Value
true if rdstate
& (badbit|failbit)
is nonzero, otherwise false.
For more information on failbit, see ios_base::iostate.
Example
// basic_ios_fail.cpp
// compile with: /EHsc
#include <iostream>
int main( void )
{
using namespace std;
bool b = cout.fail( );
cout << boolalpha;
cout << b << endl;
}
Output
false
Requirements
Header: <ios>
Namespace: std
Return Value
true if rdstate
& (badbit|failbit)
is nonzero, otherwise false.
For more information on failbit, see ios_base::iostate.
Example
// basic_ios_fail.cpp
// compile with: /EHsc
#include <iostream>
int main( void )
{
using namespace std;
bool b = cout.fail( );
cout << boolalpha;
cout << b << endl;
}
Output
false
Requirements
Header: <ios>
Namespace: std
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询