substr copies part of a string, which is useful when a record has a fixed prefix.

Extract Prefix

extract_prefix.cpp
#include <iostream>
#include <string>

int main() {
    int width = ;

    std::string code = "INV-2048";
    std::string prefix = code.substr(0, width);
    int size = static_cast<int>(prefix.size());

    std::cout << "prefix=" << prefix << std::endl;
    std::cout << "size=" << size << std::endl;
    return 0;
}
#include <iostream>
#include <string>

int main() {
    int width = ;

    std::string code = "INV-2048";
    std::string prefix = code.substr(0, width);
    int size = static_cast<int>(prefix.size());

    std::cout << "prefix=" << prefix << std::endl;
    std::cout << "size=" << size << std::endl;
    return 0;
}
#include <iostream>
#include <string>

int main() {
    int width = ;

    std::string code = "INV-2048";
    std::string prefix = code.substr(0, width);
    int size = static_cast<int>(prefix.size());

    std::cout << "prefix=" << prefix << std::endl;
    std::cout << "size=" << size << std::endl;
    return 0;
}
substr `substr(start, count)` returns a new string starting at `start` with at most `count` characters.
prefix A prefix is the leading part of a string.