C++ STL的std :: is_integral模板用于检查给定类型是否为整数。它返回一个显示相同值的布尔值。
句法:
template struct is_integral;
模板参数:此模板接受单个参数T(特质类),以检查T是否为整数类型。
返回值:该模板返回一个布尔值,如下所示:
- true :如果类型是整数。
- false :如果类型为非整数。
下面的程序说明了C++中的std :: is_integral模板:
程序1 :
// C++ program to illustrate
// is_integral function
#include
#include
using namespace std;
// main program
int main()
{
cout << boolalpha;
cout << "is_integral:" << endl;
cout << "char: " << is_integral
::value << endl;
cout << "int: " << is_integral
::value << endl;
cout << "float: " << is_integral
::value << endl;
return 0;
}
输出:
is_integral:
char: true
int: true
float: false
程序2 ::
// C++ program to illustrate
// is_integral function
#include
#include
using namespace std;
// main program
int main()
{
cout << boolalpha;
cout << "is_integral:" << endl;
cout << "double: " << is_integral
::value << endl;
cout << "bool: " << is_integral
::value << endl;
cout << "long int: " << is_integral
::value << endl;
return 0;
}
输出:
is_integral:
double: false
bool: true
long int: true
程序3 ::
// C++ program to illustrate
// is_integral function
#include
#include
using namespace std;
// main program
int main()
{
cout << boolalpha;
cout << "is_integral:" << endl;
cout << "wchar_t: " << is_integral
::value << endl;
cout << "long double: " << is_integral
::value << endl;
cout << "unsigned short int: " << is_integral
::value << endl;
return 0;
}
输出:
is_integral:
wchar_t: true
long double: false
unsigned short int: true
要从最佳影片策划和实践问题去学习,检查了C++基础课程为基础,以先进的C++和C++ STL课程基础加上STL。要完成从学习语言到DS Algo等的更多准备工作,请参阅“完整面试准备课程” 。