Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/templates/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C++11 模板错误强制转换对象_C++11_Templates_Types_Casting - Fatal编程技术网

C++11 模板错误强制转换对象

C++11 模板错误强制转换对象,c++11,templates,types,casting,C++11,Templates,Types,Casting,我有以下问题。有一个功能: int main() { //... std::string test = "1234"; std::string result = ValueToCharArray(test); //... } template<class Type> std::string ValueToCharArray(Type& value) { std::string buffer = "";

我有以下问题。有一个功能:

int main()
{
   //...
   std::string test = "1234";
   std::string result = ValueToCharArray(test);
   //...
}
template<class Type>
std::string ValueToCharArray(Type& value)
{
    std::string buffer = "";
    //...
    if (typeid(std::string) == typeid(value))
    {
        std::cout << typeid(std::string).name() << '\n' << typeid(value).name() << '\n';
        value.at(0);
        //...
    }
    short int i = 0;
    while (i<3)
    {
        buffer += '?';
        i++;
    }
    buffer[i] = 0;
    return buffer;
}
intmain()
{
//...
std::string test=“1234”;
std::字符串结果=ValueToCharray(测试);
//...
}
模板
std::字符串值到字符集(类型和值)
{
std::string buffer=“”;
//...
if(typeid(std::string)=typeid(value))
{

std::cout
std::sting::at
是C++20的新功能。它在C++11中不存在。您可以改为编写
值[0]
。第二个错误是,有人试图复制流对象(可能是通过按值传递给函数),代码中未显示的某个位置。