How to obtain nanosecond file creation time in C++

In the process of software development, I encountered a requirement to obtain the time stamps of file creation time, modification time and access time. It is easy to obtain this information by calling struct stat related interfaces, but the requirement is to obtain nanosecond timestamps. So I don't know what to do, is there someone give me a solution? By the way, I use C++ programming under Linux.


Not all file systems support this (ext4 does):

    struct stat result;
    if (stat(filename, &result) == 0) {
        printf("Last access of %s: %sns: %ld\n",
            filename,
            ctime(&result.st_ctim.tv_sec),
            result.st_ctim.tv_nsec
        );
    } else {
        fprintf(stderr, "%s: %s.\n", argv[0], strerror(errno));
    }