• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 170
  • Last Modified:

Using read and write with APvector class

I would like to create a binary file using the write but using an AP vector of structures. I can do this with a regular array of structures but there is an error when I try to use the ap vector class.
I use write((unsigned char*)arrayname, count*sizeof(structurename))
1 Solution
This is because "arrayname" is not an array.  it is an object.  it is an object that acts like an array, but is not an array.  When you try convert a real array to a character array using (unsigned char *) it allows the array to be treated like an array of bytes, i.e. as raw data.  But when you do that to an array object (vector object) it allows the object itself to be treated as raw data, but not the data stored in the array object.

You will have to iterate through each item stored in the array and write out each item, one-at-a-time.
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now