C++ min/max 函数错误 (C2665)

C++ min/max function error (C2665)

我试图让这个函数正常工作,它需要一个介于最小和最大范围之间的整数,但我一直收到错误:

No instance of overloaded function "input" matches the argument list
argument types are: (const char [##], int, int)

我尝试使用的函数如下

int input(char* t, int min, int max) {
    int number;
    do {
        cout << '\t' << t << " (" << min << '-' << max << "):  ";
        cin >> number;
        cin.ignore();
    } while (number < min || number > max);
    return number;
}

稍微解释一下。 t 参数基本上就是所问的问题,例如:"How old are you"。 minmax 都是整数。

用法示例:

int years;
years = input("How old are you", 0, 110);

是的,指针应该在函数参数中。

我得到的构建错误:C2665

如果有人有时间帮助我,请提前致谢。 (包括所有需要的库)

const char*char* 不同(字符串文字在 C++ 中是不可变的)。将函数签名更改为:

int input(const char* t, int min, int max)

更好的是,考虑使用 std::string