1

「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;
}
4

1 に答える 1

4

Console::WriteLineは CLI(C++.NET) 関数であり、それに渡すことはできません。この目的のためにstd::string使用する必要があります。System::String^

ネイティブ C++ では、次を使用する必要があります。

std::cout << "\n\nThe converted temperature is " << result
    << " degrees " << ' ' << sType << "\n\n";
于 2012-10-14T09:28:20.533 に答える