Hello, World! – Cloudywizzard

Hello, World!

Lets write the classic first program using the new C++20 language features using the std::format

import <iostream>;
import <format>;

int main()
{
    std::cout << std::format("Hello, World!") << std::cout;
    return 0;
}

Since the format module is not available yet, you can opt for the {fmt} library from https://fmt.dev) which is the library the format module is build on.

import<iostream>;
//import<format>;
#define FMT_HEADER_ONLY
#include "fmt/format.h"
using fmt::v7::format;
using fmt::v7::format_error;
using fmt::v7::formatter;
using namespace std;

int main()
{
	cout << format("Hello, World!") << endl;
	return 0;
}

I’m using the using directive to make it as easy as possible to refactor this code once std::format is available. Once it is available I only need to uncomment line 2, and delete lines 3 through 7.

You will offcourse need to install the {fmt} library first. I’m using the “shared library” option.

cd fmt-7.1.3
mkdir build
cd build
cmake -DBUILD_SHARED_LIBS=TRUE ..
make
sudo make install
sudo ldconfig

Leave a Comment

Het e-mailadres wordt niet gepubliceerd. Vereiste velden zijn gemarkeerd met *

Deze website gebruikt Akismet om spam te verminderen. Bekijk hoe je reactie-gegevens worden verwerkt.