Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8680323
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T21:13:11+00:00 2026-06-12T21:13:11+00:00

I have downloaded an image and it is saved in a std::string . Now

  • 0

I have downloaded an image and it is saved in a std::string.
Now I want to use/open it with following conditions:

typedef uint8_t byte //1 byte unsigned integer type.  
static open(const byte * data, long size)

How do I cast from string to byte* ?

/EDIT:
i have already tried this:

_data = std::vector<byte>(s.begin(), s.end()); 
//_data = std::vector<uint8_t>(s.begin(), s.end());  //also fails, same error
_p = &_data[0];
open(_p, _data.size())

but i get:
undefined reference to ‘open(unsigned char const*, long)’
why does it interpret byte wrongly as char?!

/EDIT2:
just to test it i changed to function call to

 open(*_p, _data.size())

but then i get:

error: no matching function for call to 'open(unsigned char&, size_t)'
[...] open(const byte*, long int) <near match>

So the function is definitly found…

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-12T21:13:12+00:00Added an answer on June 12, 2026 at 9:13 pm

    Two possibilities:

    1) the common one. On your system, char is either 2’s complement or else unsigned, and hence it is “safe” to read chars as unsigned chars, and (if char is signed) the result is the same as converting from signed to unsigned.

    In which case, use reinterpret_cast<const uint8_t*>(string.data()).

    2) the uncommon one. On your system, char is signed and not 2’s complement and hence for char *ptr pointing to a negative value the result of *(uint8_t*)ptr is not equal to (uint8_t)(*ptr). Then depending what open actually does with the data, the above might be fine or you might have to copy the data out of a string and into a container of uint8_t, converting as you go. For example, vector<uint8_t> v(string.begin(), string.end());. Then use &v[0] provided that the length is not 0 (unlike string, you aren’t permitted to take a pointer to the data of an empty vector even if you never dereference it).

    Non-2’s-complement systems are approximately non-existent, and even if there was one I think it’s fairly unlikely that a system on which char was signed and not 2’s complement would provide uint8_t at all (because if it does then it must also provide int8_t). So (2) only serves pedantic completeness.

    why does it interpret byte wrongly as char

    It isn’t wrong, uint8_t is a typedef for unsigned char on your system.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have the following code to download an image: imageRequest = [ASIHTTPRequest requestWithURL:[NSURL URLWithString:magazineItem.contentURL]];
I want to force the download of an image. I have found this code:
I have image on server of dimension 1000x800. I download it using following approaches:
I have tried to download images to a directory but now I want to
In my WP7 application I have downloaded 200 images from Web and saved in
i have the following code which works fine to download image form url .
I have a view that will be displaying downloaded images and text. I'd like
I have a ListView and each row has an ImageView. These Images are downloaded
I have some code that downloads an image from a remote server $data =
I'm implementing an image cache system for caching downloaded image. My strategy is based

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.