简体   繁体   English

C++ 不存在合适的构造函数来转换为

[英]C++ no suitable constructor exists to convert from to

I'm trying to make it so an input of a string gets multiplied by two the subtract 1. I know that my question has been asked here before, but the problem is that I couldn't really comprehend what it was saying was wrong.我正在尝试使字符串的输入乘以减去 1 的两倍。我知道我的问题以前在这里被问过,但问题是我无法真正理解它所说的错误。

string coffeeCode(string input) {           //Coffee code= 2n-1 where n=a number in a string

    vector<double> userInputDoubles;
    istringstream converter(input);
    string token;
    double value{};
    while (getline (converter, token, ',')) {
        value = stod(token);
        value = 2 * value - 1;
        userInputDoubles.push_back(value);

    };


    return value;
};

The function returns a double but its return type is string. function 返回一个双精度,但它的返回类型是字符串。 There is no default constructor to convert double to string.没有将双精度转换为字符串的默认构造函数。 Return a string:返回一个字符串:

std::string coffeeCode(std::string input) {           //Coffee code= 2n-1 where n=a number in a string

    std::vector<double> userInputDoubles;
    std::istringstream converter(input);
    std::string token;
    double value{};
    while (std::getline (converter, token, ',')) {
        value = std::stod(token);
        value = 2 * value - 1;
        userInputDoubles.push_back(value);

    };


    return std::to_string(value);
};

or return a double:或返回双精度:

double coffeeCode(std::string input) {           //Coffee code= 2n-1 where n=a number in a string

    std::vector<double> userInputDoubles;
    std::istringstream converter(input);
    std::string token;
    double value{};
    while (std::getline (converter, token, ',')) {
        value = std::stod(token);
        value = 2 * value - 1;
        userInputDoubles.push_back(value);

    };


    return value;
};

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 C++ 小问题:不存在合适的构造函数来从“void”转换 - C++ minor problem: no suitable constructor exists to convert from “void” C ++“没有合适的构造函数可供转换 <default constructor> 参数化构造函数 - C++ "No suitable constructor exists to convert from <default constructor> to parameterized constructor c++ 不存在合适的构造函数来将“int”转换为“std::pair”<int, int> ”</int,> - c++ no suitable constructor exists to convert from “int” to “std::pair<int, int>” 没有合适的构造函数可以从“test *”转换为“test”,构造函数, - no suitable constructor exists to convert from “test *” to “test”, constructor, C++ 没有合适的转换 function from to 存在 - C++ no suitable conversion function from to exists 不存在合适的构造函数来从void转换为std:thread - no suitable constructor exists to convert from void to std:thread 没有合适的构造函数可将“ const char [7]”转换为“ TopicA” - No suitable constructor exists to convert from “const char[7]” to “TopicA” 不存在将“哑指针”转换为“智能指针”的合适构造函数 - No suitable constructor exists to convert from “dumb pointer” to “smart pointer” 不存在将“float”转换为“_D3DCOLORVALUE”的合适构造函数 - No suitable constructor exists to convert from “float” to “_D3DCOLORVALUE” C ++不存在从“日期”到“日期(*)()”的合适转换函数 - C++ no suitable conversion function from “Date” to “Date (*)()” exists
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM