📜  C++中的std is_floating_point模板

📅  最后修改于: 2021-05-30 11:57:18             🧑  作者: Mango

C++ STL的std :: is_floating_point模板用于检查给定类型是否为浮点值。它返回一个显示相同值的布尔值。

句法:

template < class T > struct is_floating_point;

参数:此模板接受单个参数T(Trait类),以检查T是否为浮点类型。

返回值:该模板返回一个布尔值,如下所示:

  • 正确:如果类型是浮点型。
  • False:如果类型是非浮点型值。

下面的程序说明了C++ STL中的std :: is_floating_point模板:

程序1:

// C++ program to illustrate
// std::is_floating_point template
  
#include 
#include 
using namespace std;
  
// main program
int main()
{
    cout << std::boolalpha;
    cout << "is_floating_point:" << endl;
    cout << "char: "
         << is_floating_point::value
         << endl;
    cout << "int: "
         << is_floating_point::value
         << endl;
    cout << "float: "
         << is_floating_point::value
         << endl;
    return 0;
}
输出:
is_floating_point:
char: false
int: false
float: true

程式2:

// C++ program to illustrate
// std::is_floating_point template
  
#include 
#include 
using namespace std;
  
// main program
int main()
{
    cout << std::boolalpha;
    cout << "is_floating_point:" << endl;
    cout << "double: "
         << is_floating_point::value
         << endl;
    cout << "bool: "
         << is_floating_point::value
         << endl;
    cout << "long int: "
         << is_floating_point::value
         << endl;
    return 0;
}
输出:
is_floating_point:
double: true
bool: false
long int: false

程序3:

// C++ program to illustrate
// std::is_floating_point function
#include 
#include 
using namespace std;
  
// main program
int main()
{
    cout << boolalpha;
    cout << "is_floating_point:" << endl;
    cout << "wchar_t: "
         << is_floating_point::value
         << endl;
    cout << "long double: "
         << is_floating_point::value
         << endl;
    cout << "unsigned short int: "
         << is_floating_point::value
         << endl;
  
    return 0;
}
输出:
is_floating_point:
wchar_t: false
long double: true
unsigned short int: false
要从最佳影片策划和实践问题去学习,检查了C++基础课程为基础,以先进的C++和C++ STL课程基础加上STL。要完成从学习语言到DS Algo等的更多准备工作,请参阅“完整面试准备课程”