C ++未知错误

时间:2012-11-22 07:30:59

标签: syntax compiler-errors c++-cli

我在C ++中有以下功能:

std::wstring decToDeg(double input)
{
    int deg, min;
    double sec, sec_all, min_all;
    std::wstring output;

    sec_all = input * 3600;
    sec = Math::Round(static_cast<int>(sec_all) % 60, 3); //code from @spin_eight answer
    min_all = (sec_all - sec) / 60;
    min = static_cast<int>(min_all) % 60;
    deg = static_cast<int>(min_all - min) / 60;
    output = deg + L"º " + min + L"' " + sec + L"\"";

    return output;
}

当我尝试编译时,我收到此错误:

error C2679: binary '=' : no operator found which takes a right-hand operand of type 'System::String ^' (or there is no acceptable conversion)  

我可以做些什么来纠正我的功能中的这两个错误?

编辑:已解决

std::wstring decToDeg(double input)
{
    int deg, min;
    double sec, sec_all, min_all;

    sec_all = input * 3600;
    sec = Math::Round(static_cast<int>(sec_all) % 60, 3);
    min_all = (sec_all - sec) / 60;
    min = static_cast<int>(min_all) % 60;
    deg = static_cast<int>(min_all - min) / 60;

    std::wostringstream output;
    output << deg << L"º " << min << L"' " << sec << L"\"";

    return output.str();
}

4 个答案:

答案 0 :(得分:1)

sec = Math::Round(static_cast<int>(sec_all) % 60, 3);

答案 1 :(得分:1)

你不能在双打上使用模数。 Modulo on double:

 int result = static_cast<int>( a / b );
 return a - static_cast<double>( result ) * b;

答案 2 :(得分:1)

您可以使用字符串流来构建output,如下所示:

std::wostringstream output;
output << deg << L"º " << min << L"' " << sec << L"\"";

return output.str();

答案 3 :(得分:0)

对于第一个错误,请尝试:

 min = (static_cast<int>(min_all) ) % 60;

这应该确保在尝试进行任何其他计算之前先完成演员表。

如果您的其他错误不是由第一个错误引起的错误,您可能想尝试使用stringstream。它的行为类似于普通的I / O流,因此非常适合格式化字符串。

相关问题