how to find the size of a structure during programming in visual studio
c++, visual-studio-2012
Solution
Intellisense can tell you this. Example:
template <size_t S> class Sizer { };
int x;
Sizer<sizeof(x)> foo;
If you hover over `foo`, it will show `4Ui64` - the size of `x` is 4. The `Ui64` suffix is because `size_t` is Unsigned, Integral and 64 bits. Since it uses Intellisense, you don't need to compile the code. You can put `Sizer` in your `stdafx.h` precompiled header.
[update] An easier to use variant, using class template argument deduction
template <typename T, size_t = sizeof(T)> struct Sizer {
Sizer(T)
};
int x;
Sizer foo(x);
Problem
I know that the size of a structure is known at compile time, so it should be possible to find the size of a structure during programming. How can I do this? To be more specific: I have a structure say: ``` struct mystruct { int a; char b; float c[100]; } ``` I can write this line in my code and run application and see the size of this structure: ``` int size=sizeof(mystruct); cout<<"size is="<<size<<endl; ``` But this involves adding a bit of code to my application and running it. Is there any way that Visual Studio IDE can help me to find what is the size of this structure (for example by putting my cursor on it and pressing a key!)