c++ - 多次调用一个函数,但它只打印一次
问题描述
我正在运行以下代码:
#include <iostream>
using namespace std;
string response(bool isMale, bool isTall)
{
if (isMale && isTall) {
cout << "MALE AND TALL" << endl;
}
else if (isMale || isTall) {
cout << "MALE OR NOT TALL" << endl;
}
else {
cout << "ELSE" << endl;
}
}
int main()
{
response(true, true);
response(false, true);
response(false, false);
return 0;
}
输出如下:
MALE AND TALL
Process returned -1073740940 (0xC0000374) execution time : 1.460 s
Press any key to continue.
为什么没有输出?:
MALE AND TALL
MALE OR NOT TALL
ELSE
另一篇论坛帖子暗示未重置全局值。我真的不知道该怎么做。
我将不胜感激任何帮助
解决方案
void response(bool isMale, bool isTall){
if (isMale && isTall) {
cout << "MALE AND TALL" << endl;
}
else if (isMale || isTall ){
cout << "MALE OR NOT TALL" << endl;
}
else {
cout << "ELSE" << endl;
}
}
您需要将函数返回类型“string”更改为“void”。
推荐阅读
- javascript - 重置 setInterval 会将其置于多循环间隔中
- memory-management - Win64、MacOS、Linux下如何获取虚拟地址空间和单独配置内存?
- integration - 为什么我的 NetSuite 创建操作不返回任何自定义字段?
- python - PythonKit 无法为 Swift 框架加载对象(适用于 Swift 应用程序)
- java - 项目编译为jar后停止工作
- python - 将代码升级到 tensorflow 2.0 时出现 *variable 语法错误
- sas - 行标签被截断
- dataframe - 如何从 Julia 的单列 DataFrame 中提取 column_name 字符串和数据向量?
- python - ThreadPoolExecutor(workers) 增加内存使用
- angular - Angular 8,PrimeNG p-dropdown 选择默认值