|
#include <iostream>
using namespace std;
class CTestA
{
public:
virtual void FuncA()
{}
private:
int m_iValue1;
char m_cValue1;
int m_iValue2;
char m_cValue2;
double m_dValue1;
};
class CTestB : public CTestA
{
public:
virtual void FuncB()
{}
private:
};
void main()
{
cout << sizeof(CTestB) << endl;
system("pause");
}
Why the output is '32', while my expected is '28'.
|
|
|
|
|
carter2000 wrote: Why the output is '32', while my expected is '28'.
How are you calculating 28? By adding size of individual members? If yes, see what MSDN is saying.
When the sizeof operator is applied to a class, struct, or union type, the result is the number of bytes in an object of that type, plus any padding added to align members on word boundaries. The result does not necessarily correspond to the size calculated by adding the storage requirements of the individual members.
|
|
|
|
|
|
Structure sizes don't work that way - there may be (will be in this case) be padding between items of different types in a structure, dependent on the type's default alignment. Have a look at this Wikipedia page[^] that explains the concept.
However, there is a way around the default alignments, using #pragma pack to alter structure packing. So, if you put the following line before your structure definitions, you'll find you get the output you expect:
#pragma pack(1)
Java, Basic, who cares - it's all a bunch of tree-hugging hippy cr*p
|
|
|
|
|
Thanks. I add "#pragma pack(4)", and it works as I wish.
|
|
|
|
|
Not #pragma pack(1) ?
Java, Basic, who cares - it's all a bunch of tree-hugging hippy cr*p
|
|
|
|
|
Yes, not #pragma pack(1). I put it in my program, and the output was "22".
|
|
|
|
|
Hi All,
I need to remove duplicate lines in a text file, need to use that output file for other functions.
Can any one suggest me how to remove the duplicate lines in a text file
|
|
|
|
|
neeraja31 wrote: Can any one suggest me how to remove the duplicate lines in a text file
Read the file, sort the contents, discard the duplicates and write the remaining lines to a new file.
Or did I misunderstand the question?
|
|
|
|
|
Hi Thanks for yuor reply.
How can i sort the text file using C++ code.
If you have any piece of code please expain me with that
|
|
|
|
|
neeraja31 wrote: How can i sort the text file using C++ code.
The qsort() function provides a simple sort mechanism, or you could use the STL vector<> type. See the MSDN documentation for complete details.
|
|
|
|
|
neeraja31 wrote: How can i sort the text file using C++ code.
How about std::sort() ?
"Old age is like a bank account. You withdraw later in life what you have deposited along the way." - Unknown
"Fireproof doesn't mean the fire will never come. It means when the fire comes that you will be able to withstand it." - Michael Simmons
|
|
|
|
|
read text lines from file and save them to vector(or other container),
then sort the vector and unique it.
|
|
|
|
|
Please give me te\he piece of code to read from vector, confirm me whether that will work on win32 VC++ project
|
|
|
|
|
One example, assuming you are storing int s in the vector , looks like:
vector<int> nums;
for (vector<int>::iterator i = nums.begin(); i != nums.end(); i++)
cout << *i << endl;;
"Old age is like a bank account. You withdraw later in life what you have deposited along the way." - Unknown
"Fireproof doesn't mean the fire will never come. It means when the fire comes that you will be able to withstand it." - Michael Simmons
|
|
|
|
|
Hi sir..
I have created one dialog based application.when i am trying to add new member variable.It is giving the error as..
Error: object does not support this property or method
"file:///C:/Program%20Files/Microsoft%20Visual%20Studio%208/VC/VCWizards/CodeWiz/MFC/Simple/HTML/1033/default.htm"..
I have installed IE8 but i am getting the same error.
any help will be thankful..
thank you
sharan
Hi,,
I am sharan.Working as a software Engineer in Indo-Fuji Software Company located in BTM Layout.Bangalore.India.
I have Completed my B.E(COmputers)in 2006.ANd I am having 2 years of Exp in VC++.
thanking you
sharan
|
|
|
|
|
sharanu wrote: I have created one dialog based application.when i am trying to add new member variable.It is giving the error as..
Error: object does not support this property or method
What is the structure of your object, and how are you adding the new member?
sharanu wrote: I have installed IE8 but i am getting the same error.
What does this have to do with a dialog based application?
|
|
|
|
|
File system may be NTFS, FAT32, compressed or not, my question is:
when a software was installed on different OSs, Are file sizes the same under different operating systems?
i.e. the installation pack has following files: myexe.exe, myhtm.htm, mychm.chm, mytxt.txt and other types of files, do all files appear the same in sizes under different operating systems?
|
|
|
|
|
includeh10 wrote: Are file sizes the same under different operating systems?
Yes and No.
The actual size of a file in bytes will remain constant throughout the known universe; as long as 1 byte == 8 bits remains true.
However the size of the file on a storage medium (disk, DVD, memory stick etc.) varies according to the device sector size. For example if a disk has a sector size of 28 bytes then a file of 100 bytes will take up 4 sectors: 3 full sectors, plus 1 extra containing the last 16 bytes. This will give an apparent file size of 112 bytes. If the filesystem uses compression then the size on disk cannot be calculated accurately, although the file system will still return the correct size uncompressed.
|
|
|
|
|
My post is not clear according to your reply.
Exactly say:
- all files are only on harddisk (installed there)
- Functions used for calculating file size are:
- FindFirstFile(...)
or dwFileSizeLow of struct WIN32_FIND_DATA
- GetFileSize(...) or GetCompressedFileSize(...)
related to OpenFile(...)
If so, the answer is "Yes" or "Yes and No"?
modified on Sunday, September 27, 2009 8:41 AM
|
|
|
|
|
The documentation[^] says "The GetFileSize function retrieves the uncompressed size of a file. Use the GetCompressedFileSize function to obtain the compressed size of a file."
|
|
|
|
|
harold aptroot, thanks.
I modified my question.
My question is if file size obtained by functions is the same for same file installed on different OS.
I can not test, because I don't have all different OS.
|
|
|
|
|
Well it should be the same
I won't make any guarantees though, windows can be very odd..
|
|
|
|
|
includeh10 wrote: My question is if file size obtained by functions is the same for same file installed on different OS.
How important is it to know this? Since each OS provides a function to return the size of a file, then it will always return the file size on that specific OS.
includeh10 wrote: I can not test, because I don't have all different OS.
Then why do you need the information?
|
|
|
|
|
Hi sir.
I have prepared one dialog based application.If i click a button .I want open a doc file.
for example: Suppose their is a doc file in "D:\sample.doc".The document file must open.
thank you
sharan
Hi,,
I am sharan.Working as a software Engineer in Indo-Fuji Software Company located in BTM Layout.Bangalore.India.
I have Completed my B.E(COmputers)in 2006.ANd I am having 2 years of Exp in VC++.
thanking you
sharan
|
|
|
|