Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

C++ Data-Url as String to const byte *

Tags:

c++

string

byte

I have a Data-Url of a file as std:string. The base64 encoded data has to be decoded and then be passed to this function:

open (const byte *  data, long size)

So first i extract the encoded data

size_t pos = dataurl.find_first_of(',');
std::string encoded = dataurl.substr(spos + 1);

Then i use this base64 decoder

std::string decoded = base64_decode(encoded);

Well, how can i cast 'decoded' of type string to byte*? The following code produces an error

open((byte *)decoded.c_str(), decoded.size() + 1);
//>>error: 'byte' was not declared in this scope

/EDIT: so there is a typedef

typedef uint8_t     byte

the encoded data is an image!

like image 595
Alex Schneider Avatar asked Nov 24 '22 15:11

Alex Schneider


1 Answers

It looks like you are removing const. c_str() returns a const char *. Your cast should be (const byte *).

like image 99
Gort the Robot Avatar answered Dec 04 '22 20:12

Gort the Robot