Sample code for 30+ languages & platforms
C++

Duplicate openssl pkey -in private.pem -pubout -out pubkey.pem

See more OpenSSL Examples

How to output the public part of a private key: Demonstrates how to duplicate this OpenSSL command:
openssl pkey -in private.pem -pubout -out pubkey.pem

Chilkat C++ Downloads

C++
#include <CkPrivateKey.h>
#include <CkPublicKey.h>

void ChilkatSample(void)
    {
    bool success = false;

    CkPrivateKey pkey;

    //  Load the private key from an PEM file:
    success = pkey.LoadPemFile("private.pem");
    if (success == false) {
        std::cout << pkey.lastErrorText() << "\r\n";
        return;
    }

    CkPublicKey pubKey;
    pkey.ToPublicKey(pubKey);

    success = pubKey.SavePemFile(false,"pubKey.pem");
    if (success != true) {
        std::cout << pubKey.lastErrorText() << "\r\n";
        delete pubKey;
        return;
    }

    std::cout << "Success." << "\r\n";
    }