(C++) std::div
January 11, 2018 · View on GitHub
(C++) std::div
std::div is an STL function for integer division, which creates a std::div_t containing the quotient and remainder of the division.
#include <cassert> #include <cstdlib> int main() { const std::div_t d = std::div(7,3); //Assume the quotient equals (7 / 3) == 2 assert(d.quot == 2); //Assume the remainder equals (7 % 3) == 1 assert(d.rem == 1); }
The related std::ldiv function works on long ints.