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 7876497
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 3, 20262026-06-03T03:10:33+00:00 2026-06-03T03:10:33+00:00

std::vector<unsigned char> Data = example I found this on the internet somewhere and I

  • 0
std::vector<unsigned char> Data = example

I found this on the internet somewhere and I think it writes an array of bytes of unknown size to a given address but I’m not entirely sure. Can anyone explain what this does?

And if this doesn’t do what I think it does can someone help me produce a C++ function that takes an address and bytes as arguments and writes them at that address ie:

myfunction(0xaddress, {0x10, 0x11, 0x12}); // something like this
  • 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-03T03:10:34+00:00Added an answer on June 3, 2026 at 3:10 am

    If you want to write an x amount of bytes to an address, you have a number of options.

    void myfunction(void* address, size_t count, const unsigned char data[])
    {..}
    
    const unsigned char bytes[] = {0x10, 0x11, 0x12};
    myfunction (address, 3, bytes);
    

    where the second argument, count, is the length of the array.
    Or with a variadic function:

    void myfunction(void* address, size_t count, ...)
    {..}
    
    myfunction (address, 3, 0x10, 0x11, 0x12);
    

    In all cases, you’ll need to give the byte count explicitly though; the compiler can’t deduce that from the data.

    If you want to use a vector, that’s possible, but you’ll need to populate the vector first before calling the function, which isn’t as efficient.

    The only case where you wouldn’t need to provide the count yourself is if none of the bytes would have value 0, then you could write

    void myfunction(void* address, const char* str)
    {..}
    
    myfunction (address, "\x10\x11\x12");
    

    because you could use strlen!

    Edit:
    Also, std::basic_string<unsigned char> would be worth looking into. But here too, it’s not trivial to give this a value that contains \x00 values.

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

Sidebar

Related Questions

I have an std::vector<unsigned char> with binary data in. I just would like to
Which is a better c++ container for holding and accessing binary data? std::vector<unsigned char>
How would I do this using STL algorithms? std::ifstream file(filename); std::vector<unsigned char> buf; for(auto
Given std::vector<CMyClass> objects; CMyClass list[MAX_OBJECT_COUNT]; Is it wise to do this? for(unsigned int i
Simple question, how does one create a function which takes an unsigned char std::vector
Related Question: vector <unsigned char> vs string for binary data . My code uses
I have a (void*) buffer that I need to convert to std::vector<unsigned char> before
I'll start with the code: typedef std::vector<unsigned char> CharBuf; static const int RCV_BUF_SIZE =
void ServerManager::addWork(SocketClient *clientSocket, vector<char> data){ Work *work = new Work(clientSocket, data); m_workHandler->addWork(work); } Here
I have a client that sends me data using this function: void CServerRetrieve::Send(char *buf,

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.