How to use C++ htslib to read VCF contig name and size?
#include "htslib/vcf.h"

int main(int argc, char *argv[])
{
    htsFile *fp;
    bcf_hdr_t *hdr;
    bcf_idpair_t *ctg;
    int i;
    if (argc == 1) {
        fprintf(stderr, "Usage: print-ctg &lt;in.vcf&gt;\n");
        return 1;
    }
    fp = vcf_open(argv[1], "r");
    hdr = vcf_hdr_read(fp);
    ctg = hdr-&gt;id[BCF_DT_CTG];
    for (i = 0; i &lt; hdr-&gt;n[BCF_DT_CTG]; ++i)
        printf("%s\t%d\n", ctg[i].key, ctg[i].val-&gt;info[0]);
    bcf_hdr_destroy(hdr);
    vcf_close(fp);
    return 0;
}


On stability: this use has been in htslib forever. In general, functions/structs/variables in the public headers are meant to be stable. However, there is no guarantee that future versions will always keep the same APIs.