|
-
October 10th, 2004, 07:00 PM
#1
a structure with a vector as a member
Hello:
I have this interesting problem...
I have to use a c-library that contains a function that is defined as follow:
int func(char * cpData);
I have been using a structure accually a nested structure as follows
struct A
{
char cString;
char cAnotherstring;
}sA;
struct B
{
int iIndex;
float fData[MAXDATA];
}sB;
struct C
{
struct A nA;
struct B nB[8];
}sStream;
I can call this structure with now problems
using func((char *) &sStream);
I wanted to use a vector for the float fData
such as the struct B is as follows:
struct B
{
int iIndex;
vector< float> fData;
} sB;
when I call the function I getting garbaged data.
I do take care of reserving the data size.
In fact I can see that the correct data iscorrect, just prior to calling
this legecy function.
Is there a way I can convert somehow to c-array which the function understands
but be able to take advantage of the vector.
Your speedy reply wiill be vey much appreciated.
AD
-
October 10th, 2004, 08:09 PM
#2
Re: a structure with a vector as a member
I already answered this question in the other thread you had going. Maybe a mod could flip my post over here since the question/answer is not really related to that thread.
Insert entertaining phrase here
-
October 10th, 2004, 09:06 PM
#3
Re: a structure with a vector as a member
As you see I have to use a c library, and I can not do what you are suggesting
can I, I geuss May be I do not understand what you have said.
Could you elaborate more.
Thanx
AD
-
October 10th, 2004, 09:32 PM
#4
Re: a structure with a vector as a member
Well.. You are using a std::vector, so you're obiously on C++. If you serialize your struct using >>, << and std::ostream (std::ostringstream to be specific), you can still plug the result of that operation into a C function by getting a std::string of the stream (str() member-function), and passing that string to the C-function using std::string's c_str() member-function.
Insert entertaining phrase here
-
October 10th, 2004, 09:42 PM
#5
Re: a structure with a vector as a member
Note that you won't get the binary representation of the struct by using std::ostream though. Only a textual representation. If you need the binary representation, you will have to write your own serializer. I did write one myself a while back, and I would have shared, if only I could find it.
Insert entertaining phrase here
-
October 11th, 2004, 12:29 AM
#6
Re: a structure with a vector as a member
That is over my head for now.
But I will chew on it for a while
Thank you for yor time
AD
-
October 11th, 2004, 12:43 AM
#7
Re: a structure with a vector as a member
Insert entertaining phrase here
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|