C++ C++;具有数据类型名称的表

C++ C++;具有数据类型名称的表,c++,types,C++,Types,我想实现一个由一些数据类型名称组成的表,这样我就可以在循环中使用它们来coutmy函数。怎么做?我已经尝试过使用代码中的表,但它不起作用。可能是指针的问题 #include <iostream> #include <limits> #include <iomanip> using namespace std; template<typename T> void sizeF(string opis) { int x = si

我想实现一个由一些数据类型名称组成的表,这样我就可以在循环中使用它们来
cout
my函数。怎么做?我已经尝试过使用代码中的表,但它不起作用。可能是指针的问题

#include <iostream> 
#include <limits> 
#include <iomanip> 

using namespace std; 

template<typename T> 

void sizeF(string opis) { 
    int x = sizeof(T);
    if (x==1)
        cout << "Rozmiar typu "+opis+" to " << x << " bajt.\n";
    else if (x==2 || x==4)
        cout << "Rozmiar typu "+opis+" to " << x << " bajty.\n";
    else
        cout << "Rozmiar typu "+opis+" to " << x << " bajtów.\n";
} 

template<typename T> 
void maxMinF(string opis)
{
    cout << opis << ": minimalna wartosc: " << numeric_limits<T>::min() << ", maksymalna wartosc: " << numeric_limits<T>::max() << endl;
}

int main() 
{ 
    char tab[1][15] = {"short int"};
    sizeF<tab[0]>(tab[0]); 
    sizeF<int>("int");
    sizeF<unsigned long long>("unsigned long long");
    sizeF<bool>("bool");
    sizeF<char>("char");
    sizeF<double>("double");
    sizeF<long double>("long double");
    sizeF<long long>("long long");
    sizeF<short>("short");
    sizeF<unsigned short>("usigned short");

    cout << endl;

    maxMinF<short int>("short int"); 
    maxMinF<int>("int");
    maxMinF<unsigned long long>("unsigned long long");
    maxMinF<bool>("bool");
    maxMinF<char>("char");
    maxMinF<double>("double");
    maxMinF<long double>("long double");
    maxMinF<long long>("long long");
    maxMinF<short>("short");
    maxMinF<unsigned short>("usigned short");
    return 0; 
}
#包括
#包括
#包括
使用名称空间std;
模板
void sizeF(字符串opis){
int x=尺寸f(T);
如果(x==1)

我认为你在做你正在做的事情时走了一条可怕的道路

您可能应该改为参考。请看以下内容:

#包括
#包括
类小部件{
};
int main(){
小部件w1;
小部件&w2=w1;
控件常量w3;
小部件常数&w4=w1;

STD::您可以使用它来获得类型化的名称。为了使它们不被破坏,您需要使用编译器内部的特殊功能(例如:代码> ABI::Y.CXAADEMange< /Calg> GCC)。在C++中使用STD::vector:如果STD::变量不可用,则可以使用Booo::变体或使用联合:``Stult类型{联合}。{int i;无符号long long i;//其他类型}枚举类使用的类型{int type,…}std::string data;};然后是…std::vector types;``您现在可以通过UsedType枚举来区分类型。在
cout@GrzegorzGłowacki中,您能告诉我一些关于IntType的更多信息吗?接下来如何在我的函数中使用std::vector types?谢谢您的回答。我在安装增强型库时遇到了一些问题。最后我不知道如何添加它,不是吗o我在VS代码中的代码。有更简单的方法吗?@GoldenRC,坦率地说,我不知道,特别是如果你在Windows/Mac上。我在ArchLinux上,在那里安装普通的东西或前沿的东西很容易。也许你可以搜索现有的问题。我想肯定有一个。也许你可以接受我的,没有?我也添加了一个演示。。