This example shows how to parse a Swiss Payments Code into a qr_invoice object.

#include <string>
#include <iostream>

#include <qrinvoice/code_parser.hpp>
#include <qrinvoice/model/qr_invoice.hpp>
#include <qrinvoice/model/parse_exception.hpp>

// ...

std::string spc = "SPC\n"
                  "...";

try {
    qrinvoice::model::qr_invoice qrinvoice = qrinvoice::code_parser::parse(spc);

    // access QR-Invoice structure
    const double amount = qrinvoice.get_payment_amount_info().get_amount();
    std::cout << amount << std::endl;

    // ...
} catch (const qrinvoice::model::parse_exception &exception) {
    // parsing exception handling
}

Instead of only parsing the SPC it is possible to validate it just by calling the parse_and_validate method.

#include <string>
#include <iostream>

#include <qrinvoice/code_parser.hpp>
#include <qrinvoice/model/qr_invoice.hpp>
#include <qrinvoice/model/parse_exception.hpp>

// ...

std::string spc = "SPC\n"
                  "...";

try {
    qrinvoice::model::qr_invoice qrinvoice = qrinvoice::code_parser::parse_and_validate(spc);

    // access QR-Invoice structure
    const double amount = qrinvoice.get_payment_amount_info().get_amount();
    std::cout << amount << std::endl;

    // ...
} catch (const qrinvoice::model::parse_exception &exception) {
    // parsing exception handling
} catch (const qrinvoice::model::validation::validation_exception& exception) {
        std::vector<qrinvoice::model::validation::validation_result::validation_error> errors = exception.get_result().get()->get_errors();
    // ...
}

Please refer to How to Validate a QR Invoice Object for more information on the validation_result