Go back to Richel Bilderbeek's homepage.

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

 

 

 

 

 

(C++) 'Hello GMP' using Qt Creator under Ubuntu

 

Qt CreatorUbuntu

 

Hello GMP using Qt Creator under Ubuntu is straightforward: just run the project.

 

 

Operating system: Ubuntu 10.04 LTS Lucid Lynx

IDE: Qt Creator 2.0.0

Project type: console application

Compiler: G++ 4.4.1

Libraries used:

 

 

 

 

 

Qt project file

 

#-------------------------------------------------
#
# Project created by QtCreator 2010-10-01T08:45:31
#
#-------------------------------------------------
QT       += core
QT       -= gui
TARGET = CppHelloGmp
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