Go back to Richel Bilderbeek's homepage.

Go back to Richel Bilderbeek's C++ page.

 

 

 

 

 

(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.

 

 

 

 

 

Go back to Richel Bilderbeek's C++ page.

Go back to Richel Bilderbeek's homepage.

 

Valid XHTML 1.0 Strict