Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/string/5.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
String 在C++中传递字符串到函数_String_C++ Cli - Fatal编程技术网

String 在C++中传递字符串到函数

String 在C++中传递字符串到函数,string,c++-cli,String,C++ Cli,我想将像Celcius这样的字符串传递到我拥有的函数中,但我不断从函数中得到错误 System::Console::WriteLine' : none of the 19 overloads could convert all the argument types 我想我只是出了点小毛病。 有人能指出我的错误吗?使用MS Visual C++ 2010 我已经发布了违规代码。其他未发布的功能工作正常 void PrintResult( double result, std::string s

我想将像Celcius这样的字符串传递到我拥有的函数中,但我不断从函数中得到错误

System::Console::WriteLine' : none of the 19 overloads could convert all the argument types
我想我只是出了点小毛病。 有人能指出我的错误吗?使用MS Visual C++ 2010

我已经发布了违规代码。其他未发布的功能工作正常

void PrintResult( double result, std::string sType );    // Print result and string
                                                         // to the console
//=============================================================================================
//          start of main
//=============================================================================================
void main( void )
{
ConsoleKeyInfo CFM;
// Program Title and Description

ProgramDescription();

// Menu Selection and calls to data retrieval/calculation/result Print
CFM=ChooseFromMenu();
switch(CFM.KeyChar)    //     ************************************************************
    {                                                                                  //*
        case '1' : PrintResult(F2C(GetTemperature()),"Celsius");                       //*
                 break;                                                                //*
                                                                                       //*
        case '2' : PrintResult(C2F(GetTemperature()),"Fahrenheit");                    //*
                 break;                                                                //*
                                                                                       //*
        default : Console::Write("\n\nSwitch : Case !!!FAILURE!!!");                   //*
    }                       //************************************************************

system("pause");

return;
}
//Function
void PrintResult( double result, std::string sType )
{
Console::WriteLine("\n\nThe converted temperature is {0:F2} degrees {1}\n\n",result,sType);

return;
}
Console::WriteLine是一个CLIC++.NET函数,您不能将std::string传递给它,为此,您应该使用System::string^

<>在本机C++中,你应该使用:

std::cout << "\n\nThe converted temperature is " << result
    << " degrees " << ' ' << sType << "\n\n";
Console::WriteLine是一个CLIC++.NET函数,您不能将std::string传递给它,为此,您应该使用System::string^

<>在本机C++中,你应该使用:

std::cout << "\n\nThe converted temperature is " << result
    << " degrees " << ' ' << sType << "\n\n";

这看起来不像是有效的C++。除了它是无效的之外,它也不是它看起来像.NET的本地。你使用的是C++ + CLI,不仅仅是本地C++。从BigBoss看到答案。这看起来不像是有效的C++。除了它是无效的之外,它也不是它看起来像.NET.NET的原生。你使用的是C++ + CLI,不仅仅是本地C++。看看BigBoss的答案,它是我上学期做的一个C程序的转换,我们需要转换成C++。那么,我应该将函数更改为什么呢?因为如果我只是将输出行更改为std::cout,那么仍然会出现错误,并且如果我将其保留为Console::WriteLine,并且在原型中将std::string更改为System::string^,那么它会在^上变得异常。您应该使用gcnew System::string。。。代替String::String ^,GCNEXT对象的结果是一个对象,它是我上学期做的一个C程序的转换,我们需要转换成C++。那么,我应该将函数更改为什么呢?因为如果我只是将输出行更改为std::cout,那么仍然会出现错误,并且如果我将其保留为Console::WriteLine,并且在原型中将std::string更改为System::string^,那么它会在^上变得异常。您应该使用gcnew System::string。。。gcnew对象的结果是一个对象,而不是System::String^^