Returning multiple values from a C++ function

后端 未结 21 2508
别跟我提以往
别跟我提以往 2020-11-22 01:04

Is there a preferred way to return multiple values from a C++ function? For example, imagine a function that divides two integers and returns both the quotient and the rema

21条回答
  •  甜味超标
    2020-11-22 01:49

    Here, i am writing a program that is returning multiple values(more than two values) in c++. This program is executable in c++14 (G++4.9.2). program is like a calculator.

    #  include 
    # include 
    
    using namespace std; 
    
    tuple < int,int,int,int,int >   cal(int n1, int n2)
    {
        return  make_tuple(n1/n2,n1%n2,n1+n2,n1-n2,n1*n2);
    }
    
    int main()
    {
        int qut,rer,add,sub,mul,a,b;
        cin>>a>>b;
        tie(qut,rer,add,sub,mul)=cal(a,b);
        cout << "quotient= "<
                                                            
提交回复
热议问题