如何在 lambda 中返回字符串而不是布尔值
How can I return string instead of bool in lambda?
在这种情况下,如何返回字符串"x 小于 y"或"x 大于 y"而不是布尔值?
#include <iostream>
using namespace std;
int main() {
int n, m;
cin >> n >> m;
auto compare = [](int x, int y) { return x < y; };
cout << ((n == m) ? "the same" : to_string(compare(n, m)));
return 0;
}
auto compare = [](int x, int y) {
return x < y ? "x is less than y" : "x is greater than y";
};
相关文章:
- 在没有定义返回类型的函数中返回布尔值,并将结果保存在无错误的char编译中-为什么
- 变量定义到C++布尔值转换
- 如何确保在使用基于布尔值的两个方法之一调用方法时避免分支预测错误
- 提升灵气 - 将字符串解析为布尔值
- boost::带有布尔值和字符串的变体
- 检查字符串中的小写字符或空格.布尔值不起作用
- 如何在类中将布尔值更改为字符串?
- 从常量字符串到布尔值的隐式强制转换
- 尝试将字符串变量转换为布尔值会导致 "true" 和 "false" 都等于 0
- 字符串和布尔值(Int 条件为假)C++
- 使用字符串流输入/输出布尔值
- 对循环和字符串函数中的指针的操作以及布尔值
- 如何在 lambda 中返回字符串而不是布尔值
- C++字符串到布尔值
- 在C++中将字符串评估为布尔值
- C++字符串比较返回0,但布尔值返回false
- C++ - 无法从 std::基本字符串<char>转换为布尔值
- 布尔值转换为字符串,并将boolalpha与一个方法组合在一起,而不是在打印时单独键入它
- 为什么在成功将布尔字符串值转换为布尔值时,istringstream eof 标志没有变为真?
- 为什么将布尔值隐式转换为字符串不是错误?