未显示输出
Showing no output
所以我试图计算堆栈中负数的总数,并编写了这段代码,但它出现了问题,并且没有显示任何输出。我是一个c++的初学者,所以我相信这是完全错误的。
#include <iostream>
#include <stack>
using namespace std;
size_t i(stack<int> s){
int count=0;
while(s.size() !=0){
if(s.top()<0){
count++;
s.pop();
} else if(s.top()>0){
s.pop();
} else{}
cout<<count<<endl;
}
return count;
}
int main(){
stack<int> s;
s.push(-1);
s.push(2);
s.push(-2);
size_t i(stack<int> s);
return 0;
}
在main()
函数中,如果不调用i()
,只需重新声明即可。
#include <iostream>
#include <stack>
using namespace std;
size_t i(stack<int> s){
int count=0;
while(s.size() !=0){
if(s.top()<0){
count++;
s.pop();
} else if(s.top()>0){
s.pop();
} else{}
cout<<count<<endl;
}
return count;
}
int main(){
stack<int> s;
s.push(-1);
s.push(2);
s.push(-2);
size_t i(stack<int> s); // this DOES NOT call the function
i(s); // <== THIS calls the function!!!
return 0;
}
您的语句size_t i(stack<int> s);
不调用该函数,它只是"告诉"编译器它接受什么参数以及它的返回类型
相关文章:
- 了解 Linux 虚拟内存:valgrind 的 massif 输出显示了有和没有 --pages-as-heap 的主要差异
- 输出显示多个带整数的字符串值
- 如何使代码的输出显示为"工资减税"
- 如何让我的输出显示输入金额的星号
- 控制台输出显示ASCII值,而不是数字的预期数字
- 如何修复输出显示,以便显示正确排序的数据
- Android Studio 3.2:cmake message()输出显示在哪里
- 如何将OpenCV的输出显示或流式传输到HTML页面或其他一些客户端应用程序
- 我写了一个函数来删除循环链接列表中的第 1 个节点,但输出显示无限次"55 44 33 22 11 99",那么我该如何解决呢?
- 从c++程序运行shell脚本会自动将shell脚本的输出显示到控制台吗
- 为什么我的输出显示显示计算器中的每个选项
- C++将输出显示到php中
- 从 PHP 调用 C++ 应用程序 - 输出显示"Array"
- 有没有办法C++让循环的输出显示在同一行上
- 为什么日志输出显示在控制台主机中,而不显示在ISE中?(v4.0)
- 如何让GDB为每一行输出显示时间戳
- 为什么输出显示为无符号数
- 如何获得gdb tui汇编输出显示指令
- 为什么输出显示错误
- FFTW输入输出显示DSP