C++ 检查编写器功能挑战

C++ 检查编写器功能挑战,c++,function,C++,Function,Sulton Mundo,我一直在研究这个函数,它根据数字在支票上打印字母。唯一的问题是我把它变成了一个void,我不知道如何从void->string转换。如果你问我,基本上不可能。简而言之,我如何重写它,使其返回一个字符串 return ss.str(); 我的代码如下: void numALet(string &can) { int conNum= atoi(can.c_str()); float conNumF= atof(can.c_str());

Sulton Mundo,我一直在研究这个函数,它根据数字在支票上打印字母。唯一的问题是我把它变成了一个void,我不知道如何从void->string转换。如果你问我,基本上不可能。简而言之,我如何重写它,使其返回一个字符串

return ss.str();
我的代码如下:

void numALet(string &can)
{
    int conNum= atoi(can.c_str());
    float conNumF= atof(can.c_str());

    //Snippet to find the Cents.
    float cen= (int)((conNumF- conNum)* 100);

    string basic[20]= { " ", "One", "Two", "Three", "Four", "Five", "Six", "Seven", "Eight", "Nine", "Ten",
                        "Eleven", "Twelve", "Thirteen", "Fourteen", "Fifteen", "Sixteen", "Seventeen", "Eighteen", "Nineteen"},

           diez[9]= { "Ten", "Twenty", "Thirty", "Forty", "Fifty", "Sixty", "Seventy", "Eighty", "Ninety"};

    if(conNum< 20)
        cout<< basic[conNum]<< " and "<< (cen+ 1) << " Cents.";
    else if(conNum< 100 && conNum> 19)
    {
        int num= conNum% 100;
        if(num% 10!= 0)
            cout<< diez[num/10- 1]<< " "<< basic[num% 10]<< " and "<< (cen+ 1) << " Cents.";
        else
            cout<< diez[conNum/ 10- 1]<< " and "<< (cen+ 1)<< " Cents.";
    }
    else if(conNum> 99 && conNum< 1000)
    {
        int num1= conNum% 1000;
        cout<< basic[num1/ 100]<< " "<< "Hundred ";
        int num2= conNum% 100;

        if(conNum< 20)
            cout<< basic[num2]<< " and "<< (cen+ 1) << " Cents.";
        else if(num2< 100 && num2> 19)
        {
            if(num2% 10!= 0)
                cout<< diez[num2/ 10- 1]<< " "<< basic[num2% 10]<< " and "<< (cen+ 1) << " Cents.";
            else
                cout<< diez[num2/ 10- 1]<< " and "<< (cen+ 1) << " Cents.";
        }
    }
    else if(conNum> 999 && conNum< 10000)
    {
        cout<< basic[conNum/ 1000]<< " "<< "Thousand ";
        int num1= conNum% 1000;
        cout<< basic[num1/ 100]<< " "<< "Hundred ";
        int num2= conNum% 100;

        if(conNum< 20)
            cout<< basic[num2]<< " and "<< cen << " Cents.";
        else if(num2< 100 && num2> 19)
        {
            if(num2% 10!= 0)
                cout<< diez[num2/ 10- 1]<< " "<< basic[num2% 10]<< " and "<< (cen) << " Cents.";
            else
                cout<< diez[num2/ 10- 1];
        }
    }
}
void numALet(字符串和can)
{
int conNum=atoi(can.c_str());
float conNumF=atof(can.c_str());
//找到美分的代码片段。
浮点数cen=(整数)((conNumF-conNum)*100);
字符串基本[20]={”、“一”、“二”、“三”、“四”、“五”、“六”、“七”、“八”、“九”、“十”,
“十一”、“十二”、“十三”、“十四”、“十五”、“十六”、“十七”、“十八”、“十九”,
diez[9]={“十”、“二十”、“三十”、“四十”、“五十”、“六十”、“七十”、“八十”、“九十”};
如果(连接<20)

cout首先,包括lib:

#include <sstream>
替换
coutus使用a而不是
cout
,并将流作为函数参数传递,或者让函数返回对流调用
str()
的结果。@Birdie:Suggestion:。
return ss.str();