首页 > 解决方案 > 我应该按照问题陈述打印 5,4,3,2,1,但是我的 c++ 代码显示了一些错误

问题描述

我得到的错误

F:\coding\code blocks\hello.cpp|14|error: no match for 'operator<<' (操作数类型是 'std::ostream {aka std::basic_ostream}' 和 'void')|

我的代码

    #include <iostream>
    using namespace std;

    void fun(int n)
    {

        if (n==0) return;
        cout<<n<<endl;
        fun(n-1);
    }
    int main()
    {

        cout << fun(5)<< endl;

    }

标签: functionrecursionc++14

解决方案


int 主要功能。而不是写

cout<<fun(5)<<endl;

像这样写。

有趣(5);


推荐阅读