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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T08:38:50+00:00 2026-06-05T08:38:50+00:00

I have a vector object that contains clipboard data. I am trying to write

  • 0

I have a vector object that contains clipboard data. I am trying to write the contents of the clipboard data into a temp file using a buffered stream. I am using iterators to access the contents of the vector.

I am running into trouble while trying to convert the clipboard data which is a std::vector ClipboardDataVector to inbuffer which of type const std::uint8_t* inBuffer.

Here is the code that I use

typedef std::vector ClipboardDataVector;

File::WriteBlock(const std::uint8_t* inBuffer, std::uint32_t inBufferSize);

BOOL WriteToTempFile(ClipboardDataVector& clipBoardData) { 
  std::vector::iterator clipBoardIterator; 
  clipBoardIterator = clipBoardData.begin();
  File::WriteBlock((const uint8_t *)clipBoardIterator, clipBoardData.size());
}

When I compile this code I get the following error.

error C2440: ‘type cast’ : cannot convert from ‘std::_Vector_iterator<_Myvec>’ to ‘const uint8_t *’

I am new to vectors and I am finding it hard to get my head around this error – how can I resolve it?

  • 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-05T08:38:52+00:00Added an answer on June 5, 2026 at 8:38 am

    When you use a std::vector you need to specify the type it holds. So your typedef needs to be:

    typedef std::vector<uint8_t> ClipboardDataVector;
    

    Once you’ve done that if you have a vector of that type and you want to get a const uint8_t * the usual idiom is:

    void WriteToTempFile(const ClipboardDataVector& clipBoardData) {
       const uint8_t *data = clipBoardData.size() ? &clipBoardData[0] : NULL;
       // ...
    }
    

    This works because vectors have contiguous storage – it’s asking for a pointer to the first element in the vector. It also checks for the special case where the vector is empty and so the subscript operator can’t be used. This clearly won’t work for something like std::list where the elements aren’t always contiguous.

    You were on the right sort of track with iterators, but iterators are a generalisation of the concept of a pointer – that is they look and feel like a pointer (by either being a pointer or some operator overloading) but they’re not necessarily going to actually be a pointer always. If you need a pointer from a vector (because you’re interacting with C usually) then the address of the first element is the safe, portable way to do it.

    (I also made the reference to clipBoardData be const also – it’s a good habit to be in, marking things you won’t alter as const always)

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

Sidebar

Related Questions

I have a file that contains java serialized objects like Vector. I have stored
I have a class that contains a vector of object pointers. I have a
I have created a Vector object to store data in Table object as Vector<Table>
I have a C++ std::vector denoted as: std::vector<GameObject*> vectorToSort; Each object in vectorToSort contains
I have a class header file called Grid.h that contains the following 2 private
I'm trying to write a class which contains several std::vectors as data members, and
What I have in my project is the binary file that contains list of
I have a singleton logger that contains a vector. Objects from outside can append
I have a zoo object in R that has daily data and is missing
I have two vector objects that contain different types of data that are ordered

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.