(C++) ClnExample2

February 24, 2017 · View on GitHub

 

 

 

 

 

(C++) ClnExample2

 

CLNSTLQt
CreatorLubuntu

 

CLN example 2 is a CLN example that shows how to to convert an cln::cl_I to std::string and adding the thousands seperators.

Technical facts

 

Operating system(s) or programming environment(s)

IDE(s):

Project type:

C++ standard:

Compiler(s):

Libraries used:

  • Qt Qt: version 5.4.1 (32 bit)
  • STL STL: GNU ISO C++ Library, version 4.9.2

 

 

 

 

 

Qt project file: ./CppClnExample2/CppClnExample2.pro

 


#------------------------------------------------- # # Project created by QtCreator 2010-09-07T13:43:44 # #------------------------------------------------- QT       += core QT       -= gui LIBS += -L/usr/local/lib -lcln TARGET = CppClnExample2 CONFIG   += console CONFIG   -= app_bundle TEMPLATE = app SOURCES += main.cpp

 

 

 

 

 

./CppClnExample2/main.cpp

 


//--------------------------------------------------------------------------- #include <iostream> #include <string> //--------------------------------------------------------------------------- #include <boost/lexical_cast.hpp> //--------------------------------------------------------------------------- #include <cln/cln.h> //--------------------------------------------------------------------------- ///IntToStrWithSep converts an integer to std::string ///and adds thousands seperators. ///From http://www.richelbilderbeek.nl/CppIntToStrWithSep.htm const std::string IntToStrWithSep(cln::cl_I i) {   std::string s     = boost::lexical_cast<std::string>(cln::mod(i,10));   i = cln::floor1(i,10);   int d = 1;   while (!cln::zerop(i))   {     s = boost::lexical_cast<std::string>(cln::mod(i,10))       + (d % 3 == 0 ? "," : "")       + s;     i = cln::floor1(i,10);     ++d;   }   return s; } //--------------------------------------------------------------------------- int main() {   const cln::cl_I i("123456789012345678901234567890");   std::cout << "i without seperators: " << i << '\n';   const std::string s = IntToStrWithSep(i);   std::cout << "i with seperators: " << s << '\n'; } //---------------------------------------------------------------------------