Go back to Richel Bilderbeek's homepage.

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

 

 

 

 

 

(C++) std::ldiv

 

std::ldiv is an STL function for long integer division, which creates a std::ldiv_t containing the quotient and remainder of the division.

 

#include <cassert>
#include <cstdlib>

int main()
{
  const long int i = 7;
  const long int j = 3;
  const std::ldiv_t d = std::ldiv(i,j);
  //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::div function works on ints.

 

 

 

 

 

 

 

 

 

Technical facts

 

Application type(s)

Operating system(s) or programming environment(s)

IDE(s):

Project type:

C++ standard:

Compiler(s):

Libraries used:

 

 

 

 

 

Qt project file: CppLdiv.pro

 

 

TEMPLATE = app
CONFIG += console
CONFIG -= qt
SOURCES += main.cpp

 

 

 

 

 

main.cpp

 

#include <cassert>
#include <cstdlib>

int main()
{
  const long int i = 7;
  const long int j = 3;
  const std::ldiv_t d = std::ldiv(i,j);
  //Assume the quotient equals (7 / 3) == 2
  assert(d.quot == 2);
  //Assume the remainder equals (7 % 3) == 1
  assert(d.rem == 1);
}

 

 

 

 

 

 

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

Go back to Richel Bilderbeek's homepage.

 

Valid XHTML 1.0 Strict

This page has been created by the tool CodeToHtml