Horje
return multiple values c++ Code Example
c++ return multiple values
#include <tuple>

std::tuple<int, int> divide(int dividend, int divisor) {
    return  std::make_tuple(dividend / divisor, dividend % divisor);
}

#include <iostream>

int main() {
    using namespace std;

    int quotient, remainder;

    tie(quotient, remainder) = divide(14, 3);

    cout << quotient << ',' << remainder << endl;
}
return multiple values c++
#include<bits/stdc++.h>
using namespace std;
  
// A Method that returns multiple values using
// tuple in C++.
tuple<int, int, char> foo(int n1, int n2)
{
    // Packing values to return a tuple
    return make_tuple(n2, n1, 'a');             
}
  
// A Method returns a pair of values using pair
std::pair<int, int> foo1(int num1, int num2)
{
    // Packing two values to return a pair 
    return std::make_pair(num2, num1);            
}
  
int main()
{
    int a,b;
    char cc;
      
    // Unpack the elements returned by foo
    tie(a, b, cc) = foo(5, 10);      
      
    // Storing  returned values in a pair 
    pair<int, int> p = foo1(5,2);  
      
    cout << "Values returned by tuple: ";
    cout << a << " " << b << " " << cc << endl;
      
    cout << "Values returned by Pair: ";
    cout << p.first << " " << p.second;
    return 0;
}




Cpp

Related
arduino funktion Code Example arduino funktion Code Example
inconsequential meaning Code Example inconsequential meaning Code Example
if statement C++ Code Example if statement C++ Code Example
ascii conversion cpp Code Example ascii conversion cpp Code Example
cpp read csv Code Example cpp read csv Code Example

Type:
Code Example
Category:
Coding
Sub Category:
Code Example
Uploaded by:
Admin
Views:
8