c++ - Converting hex data stored as a string into a file -


preface:

i making simple program in c++ involves font. when executes creates data folder includes text files readme, haven't found way automatically create .ttf program needs display text. first instinct open .ttf in text editor , try writing text file, of course didn't work.

problem:

i have file converted hex data this

00 01 00 00 00 10 00 40 00 04 00 c0 4f 53 2f 32 80 8f 7e ff 00 00 8e b8 00 00 00 4e 50 43 4c 54 ... 2298 more lines 

i feel though should able hard code hex data string located within project, , should able use data create .ttf file when program executes. unfortunately have not yet found way.

given string looks above (or 1 make using find/replace), how go creating working .ttf file?

first hex data file, might this

00 01 00 00 00 10 00 40 00 04 00 c0 4f 53 2f 32 80 8f 7e ff 00 00 8e b8 00 00 00 4e 50 43 4c 54 ... 

then, use text editor regex support (like sublime text) data looking this

{0x00, 0x01, 0x00, 0x00, 0x00, 0x10, 0x00, 0x40, 0x00, 0x04, 0x00, 0xc0, 0x4f, 0x53, 0x2f, 0x32, 0x80, 0x8f, 0x7e, 0xff, 0x00, 0x00, 0x8e, 0xb8, 0x00, 0x00, 0x00, 0x4e, 0x50, 0x43, 0x4c, 0x54, ...} 

wherever wish, define file output data to

std::ofstream file; file.open("<path>", std::ios::binary); 

create new .cpp following array since large , unwieldy. created class 1 function writehextofile(std::ofstream& file) , put below in it

size_t data_len = <number of elements in array> unsigned char data[data_len] = {<from above>} file.write((char *)&data[0], data_len); 

now, defined ofstream file, call writehextofile(file) , close out file.close()


Comments

Popular posts from this blog

dns - How To Use Custom Nameserver On Free Cloudflare? -

python - Pygame screen.blit not working -

c# - Web API response xml language -