测试C++编译器版本
作者:
白洲アズサ
,
2021-11-23 19:19:43
,
所有人可见
,
阅读 639
输出编译器版本及当前编译环境下的C++版本, 可以用下面代码实现
#include <bits/stdc++.h>
using namespace std;
std::string cpp_standard()
{
auto VER = __cplusplus;
if (VER < 201103) return "C++98";
else if(VER == 201103) return "C++11";
else if(VER == 201402) return "C++14";
else if(VER == 201703) return "C++17";
else return "C++20";
}
std::string ver_string(int a, int b, int c)
{
std::ostringstream ss;
ss << a << '.' << b << '.' << c;
return ss.str();
}
std::string true_cxx =
#ifdef __clang__
"Clang++";
#else
"G++";
#endif
std::string true_cxx_ver =
#ifdef __clang__
ver_string(__clang_major__, __clang_minor__, __clang_patchlevel__);
#else
ver_string(__GNUC__, __GNUC_MINOR__, __GNUC_PATCHLEVEL__);
#endif
signed main()
{
cout << true_cxx << ' ' << true_cxx_ver << '\n';
cout << "Now C++ standard: " << cpp_standard();
}
输出当前CPU
#include <bits/stdc++.h>
#include <cpuid.h>
using namespace std;
using F = uint32_t;
static void cpu(F X, F Y, F msg[4])
{
__cpuid_count(X, Y, msg[0], msg[1], msg[2], msg[3]);
}
signed main()
{
F data[4]; char msg[50];
for (int i = 0;i < 3;++i)
{
cpu(0x80000002 + i, 0, data);
for (int j = 0;j < 4;++j)
reinterpret_cast<F *>(msg)[i * 4 + j] = data[j];
}
cout << msg;
}
orz