Passing a string to a function in C++

Posted by Chef Flambe on Stack Overflow See other posts from Stack Overflow or by Chef Flambe
Published on 2012-10-14T09:10:56Z Indexed on 2012/10/14 9:37 UTC
Read the original article Hit count: 147

Filed under:
|

I want to pass a string like "Celcius" into a function that I have but I keep getting errors tossed back at me from the Function.

System::Console::WriteLine' : none of the 19 overloads could convert all the argument types

I figure I just have something simple wrong. Can someone point out my mistake please? Using MS Visual C++ 2010

I've posted the offending code. The other functions (not posted) work fine.

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

© Stack Overflow or respective owner

Related posts about string

Related posts about c++-cli