Returning multiple values from a C++ function

后端 未结 21 2986
别跟我提以往
别跟我提以往 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:50

    For returning two values I use a std::pair (usually typedef'd). You should look at boost::tuple (in C++11 and newer, there's std::tuple) for more than two return results.

    With introduction of structured binding in C++ 17, returning std::tuple should probably become accepted standard.

提交回复
热议问题