|
You could Serialize out the number of books written before the serialized books. Then on deserialize read the number of books, create the books and read them back in.
Ant.
I'm hard, yet soft. I'm coloured, yet clear. I'm fuity and sweet. I'm jelly, what am I? - David Williams (Little Britain)
|
|
|
|
|
Yes that is what I thought I must do. I think it is very easy to do this way but someone else has suggested using a CList member and to call its serialization support.
|
|
|
|
|
This works, but personally, I only use this method to serialize data which the datatype is not supoorted by Serialization, like TCHAR*.
regards,
Rodrigo Pinho Pereira de Souza
|
|
|
|
|
Hello people, I'm trying to learn a few more of C++ once that I know another language. My question is... I have an array of unsigned char like this "unsigned char myArr[6]" and I want to get these values and show them into a Static Text (Visual C++) and I don't know how to convert these unsigned char array to char* or any type of "string". Can anyone help me?
thanks!
Wender Oliveira
.NET Programmer
|
|
|
|
|
Try it.
char myArr[6];
SetDlgItemText(ID_EDIT, myArr);
If you are beginner with Visual C, I suggest you to use MFC classes, Then, you will get CString class, that are similar to String from .Net
Enjoy it.
Rodrigo Pinho Pereira de Souza
|
|
|
|
|
pinhopro wrote:
SetDlgItemText(ID_EDIT, myArr);
no way. it is only if you consider that one of the 6 chars of the array contain a '\0'
no, to display each char, prefer that :
CString str;
<font style="color:blue;">char </font>myArr[6];
<font style="color:green;">
str.format(<font style="color:purple;">"%c%c%c%c%c%c"</font>, myArr[0], myArr[1], myArr[2], myArr[3], myArr[4], myArr[5]);
<font style="color:green;">
((CStatic*)GetDlgItem(IDC_MYSTATIC))->SetWindowText(str);
TOXCCT >>> GEII power
|
|
|
|
|
Wender, I have not logged many hours on Visual C++ .net but I think what you are asking to do is called a cast. Changing one type to another. However, an array really is a pointer as your myArr[0] would be the address of the array. So if you said printf("%s\n", myArr); your getting the all 6 items as opposed to: printf("%s\n", myArr[1]); where you will get the first character.
|
|
|
|
|
Anonymous wrote:
myArr[0] would be the address of the array
myArr would be the address, it is an unsigned char*. myArr[0] is the first character in the array.
Anonymous wrote:
So if you said printf("%s\n", myArr); your getting the all 6 items
No! There is only room for 6 characters in array and the last character must be '\0', so you would be printing only the first characters
Anonymous wrote:
printf("%s\n", myArr[1]); where you will get the first character.
This is just wrong! myArr[1] is the second, not the first charater and it is not a string pointer, so the results will be undefined. The %s expects a string pointer not a character value.
INTP
|
|
|
|
|
Assuming you want to display all 6 characters then you need to set the array size to 7, since the last character must be '\0'.
Exmaples:
1) unsigned char myArr[7]={"012345\0"};
2) unsigned char myArr[7];
myArr[0] = '0';
myArr[1] = '1';
myArr[2] = '2';
myArr[3] = '3';
myArr[4] = '4';
myArr[5] = '5';
myArr[6] = '\0';
Now it you want a char* insted of a unsigned char* just cast it: (char*)myArr. This is safe because both unsigned char and char are the same size.
There are other ways, but why make life difficult.
INTP
|
|
|
|
|
HI,
Wt r the Differnces between Structures and Classes
one i know is its Defualt Access specifiers.
in structure it is Public. and in Class it is Private.
tell me more
thanx
|
|
|
|
|
|
As i think we can add methods to Structure tooo
is it ?
any other difference
Assume it was interview Question to me
|
|
|
|
|
You can add methods to structures. I can only see that you can't inherit from structures. No polymorphism.
Ant.
I'm hard, yet soft. I'm coloured, yet clear. I'm fuity and sweet. I'm jelly, what am I? - David Williams (Little Britain)
|
|
|
|
|
it means simply that if we not inherit structures ,,
then we can not attain the Concepts of OOP with structers.. is it.
any other difference ??
thanx
|
|
|
|
|
I can't think of any other difference.
Ant.
I'm hard, yet soft. I'm coloured, yet clear. I'm fuity and sweet. I'm jelly, what am I? - David Williams (Little Britain)
|
|
|
|
|
Antony M Kancidrowski wrote:
I can only see that you can't inherit from structures.
Have you not seen the CRect class? It is derived from the tagRECT struct. This is perfectly legal:
struct s
{
};
class c : public s
{
};
"When I was born I was so surprised that I didn't talk for a year and a half." - Gracie Allen
|
|
|
|
|
That isn't a struct inheriting from a struct, which is what I meant. Point taken however.
Ant.
I'm hard, yet soft. I'm coloured, yet clear. I'm fuity and sweet. I'm jelly, what am I? Muse on it further, I shall return! - David Williams (Little Britain)
|
|
|
|
|
Antony M Kancidrowski wrote:
That isn't a struct inheriting from a struct, which is what I meant.
But this is:
struct s1
{
};
struct s2 : public s1
{
};
"When I was born I was so surprised that I didn't talk for a year and a half." - Gracie Allen
|
|
|
|
|
OK, I have learnt something new. I have never seen such a struct definition. Noted and commited to memory.
Thanks David
Ant.
I'm hard, yet soft. I'm coloured, yet clear. I'm fuity and sweet. I'm jelly, what am I? Muse on it further, I shall return! - David Williams (Little Britain)
|
|
|
|
|
in c++, a class and a struct are the same, except that in the case of a struct, members are public by default, and in a class, members are private by default.
Maximilien Lincourt
Your Head A Splode - Strong Bad
|
|
|
|
|
2)C++ structure and C++ class
Actually, C++ structure and C++ class are very closely realated. With one exception, they are interchangeable because the structure can also include the data, and the code that manipulates that data, in just the same way that a class can. The only difference between a C++ structure and a class is that, by default, the members of a class are private, while the members of a structure are public (This also clears up an error I made in the first lab). Aside from this distinction, structures and classes perform exactly the same function.
Here is an example of a structure that uses its class-like features.
One last point just in case you are curious about it. A structure defines a class type. Thus, a structure is a class. This was intentional on the part of the inventor of C++ -- Bjarne Stroustrup. He believed that if structures and classes were made more or less equivalent, the transition from C to C++ would be eased.
http://www.cs.uregina.ca/links/class-info/210/LabFAQ/
There it is...
"If I don't see you in this world, I'll see you in the next one... and don't be late." ~ Jimi Hendrix
|
|
|
|
|
There's nothing more to tell. In C++ a struct is a class with public access to members and public inheritance by default. They have all the same features.
|
|
|
|
|
Technically, that is the only difference.
From a conceptual standpoint, though, struct is customarily used for entities that just serve as convenient buckets to hold data, where class isused for objects.
"Fish and guests stink in three days." - Benjamin Franlkin
|
|
|
|
|
Hi!
I need to know how do i find out the time required to copy a set of files on the disk.
The explorer can tell me how much more time is needed to copy the files. ("35 seconds remaining" kinds).
What are the API's that I can use for this purpose.
Thanks in advance,
Pavan.
|
|
|
|
|
pavanhere wrote:
What are the API's that I can use for this purpose.
I don't think there is such an API.
I think explorer is dynamically estimating that time, possibly based on transfer speed and file size.
I Dream of Absolute Zero
|
|
|
|