小编SKR*_*EFI的帖子

如何使此函数使用getline读取字符串并使用int执行相同的操作?

template<typename T>
T get(const string &prompt)
{
    cout<<prompt;
    T ret;
    cin>>ret;
    return ret;
}
Run Code Online (Sandbox Code Playgroud)

我不知道如何通过重载来做到这一点; 基本上,这适用于任何类型的数据,对......

我尝试了typeid(variable).name();并获得了一个字符串变量的输出,并尝试在get函数中创建一个if.但它没有用.

c++ string templates overloading getline

5
推荐指数
1
解决办法
102
查看次数

标签 统计

c++ ×1

getline ×1

overloading ×1

string ×1

templates ×1