Go back to Richel Bilderbeek's homepage.

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

 

 

 

 

 

(C++) Hello GMP

 

Hello GMP is an extension of Hello World. Like Hello World, Hello GMP is a simple console application. Hello GMP, however, also requires the GMP library and to link against it.

 

Here are some detailed examples of Hello GMP, depending on IDE and operating system:

 

 

 

 

 

 

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: CppHelloGmp.pro

 

QT       -= core gui
TARGET = CppHelloGmp
QMAKE_CXXFLAGS += -Wextra -Weffc++ -Werror
unix:LIBS+= -L/usr/lib -lgmp
CONFIG   += console
CONFIG   -= app_bundle
TEMPLATE = app
SOURCES += main.cpp

 

 

 

 

 

main.cpp

 

#include <iostream>
#include <gmpxx.h>

///From http://www.richelbilderbeek.nl/CppMpz_tToStr.htm
const std::string Mpz_tToStr(const mpz_t& i)
{
  static char buffer[256];
  mpz_get_str(buffer,10,i);
  return std::string(buffer);
}

int main()
{
  mpz_t i;
  mpz_init_set_str(i,"123456789012345678901234567890",10);
  //Perform i = i * i
  mpz_mul(i,i,i);

  std::cout
    << "Hello GMP,\n"
    << Mpz_tToStr(i) << " times.\n";

  mpz_clear(i);
}

 

 

 

 

 

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

Go back to Richel Bilderbeek's homepage.

 

Valid XHTML 1.0 Strict