函数读取最大和min int值,并用文本字符串返回
Function reads max and min int value, returns it - with text string
我得到了一个返回数字的函数。但是,在使用该功能时,似乎我在使用该功能时做错了什么,在我没有像指针一样使用它 - 但是我该怎么做?
'read':两个超载都不能转换所有参数类型是我遇到的错误。
这是代码:
int nr = read("This is a test", 0000, 9999);
cout << nr;
int read(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;
}
如果您更详细地查看错误消息,您可能会看到类似" const char*"转换为" cont char*"的内容。
字符串文字具有" const char*"类型,因此您的读取方法必须为:
int read(const char* t, int min, int max) {
相关文章:
- 如何在C++中以这种方式返回一行文本?
- 返回从字符串文本创建的静态string_view是否安全?
- fscanf 在尝试返回文本文件的第一行时返回 -1
- 基于模板字符串文本返回的 c++ 函数指针
- std::string::find 为取消引用的迭代器和等效字符串文本返回不同的值
- 我想读取文本文件中的所有内容(但文本文件中只有一个双精度值),转换为双精度值并返回值
- FindResource 调用返回 RCDATA 类型的文本文件的 NULL
- 我的代码一直返回0作为文本文件中的小数数
- 函数读取最大和min int值,并用文本字符串返回
- 问题 - 递归函数以返回文本文件排列
- C++程序不返回文件中文本和字符串数据的值
- 搜索文本文件并返回等号后的值
- 任何人都知道如何解决尝试将从MySQL数据库返回的行打印到文本文件(.txt)中的C++
- 有没有更好的方法可以从静态和非静态函数返回相同的字符串文本
- 使用关键字从文本文件返回数字
- 获取 Poco 返回的错误代码的文本
- 为什么此代码只能识别文本文件中的第一行?输入任何大于 1 的数字都会返回"Atomic Number Not Found"
- 检查文本文件中的 0 或 1,并根据结果返回
- 通过fscanf()获取文本文件中的所有字符将返回无效的字符计数
- G++ 将返回的字符串文本视为常量字符指针而不是常量字符数组