English 中文(简体)
C++ 指示点问题
原标题:C++ Struct pointer question

This is probably simple, but im trying to try and understand pointers better. Lets say I have a struct

struct Person{
  char Name[20];
  char ID[15];
  char Address[50];
  char Number[15];
};

and lets say I have a bunch of these stored in memory like one after the other. so now i declare a new pointer to the struct.

struct Person *ptr;

该名点人是否会在飞行情报区进入时开始? (a) 第一个“Name”和当Ierate it(aka ptr++)时,它将前往下届《防止母婴传播公约》或下一个“入境”卡,如名称和编号;ID-->

因此,举例来说,首先要说的是:

Jason Adams
111222333
111 Fake Drive
55555551000

第二条目

Matt Johns
111555333
555 Derp lane
1000022434

现在,我把粉碎(ptr++)的 point点推到第二层(一个有 m子的 j子)或指向Jason Adams的“ID”

我希望这确实有意义?

最佳回答

它将指出第二个方向。 点名将采用<代码>(Person)。

问题回答

正如约翰提到的那样,它将按其规模——个人(Person)——来推进。

然而,点人操纵是徒劳的,你可以做像把点人 cast到另一种类型。 一旦你这样做,点算法将按类型的根本大小推进。 通常,请见(按顺序排列的)或(未签名的果园*)的点数,以便个人可以随意查阅基本数据。

首先,在使用之前,你必须把记忆分配给你的耳光。

auto_ptr<Person> ptr(new Person); //auto_ptr for automatic freeing

之后,你可以尝试低于法典。

strcpy(ptr->ID, "100"); //For illustraction
int offset = ptr->ID - ptr->Name; //Get offset of ID member
char *pID = ((char *)ptr.get())+ offset;
//Typecast to char pointer and increment by offset to get to ID field
cout<<pID; //Now pId can be used to access ID.

你们问,如何通过减幅获得ID属性。

如上文所述,你可以接触到国际发展学会成员。





相关问题
Undefined reference

I m getting this linker error. I know a way around it, but it s bugging me because another part of the project s linking fine and it s designed almost identically. First, I have namespace LCD. Then I ...

C++ Equivalent of Tidy

Is there an equivalent to tidy for HTML code for C++? I have searched on the internet, but I find nothing but C++ wrappers for tidy, etc... I think the keyword tidy is what has me hung up. I am ...

Template Classes in C++ ... a required skill set?

I m new to C++ and am wondering how much time I should invest in learning how to implement template classes. Are they widely used in industry, or is this something I should move through quickly?

Print possible strings created from a Number

Given a 10 digit Telephone Number, we have to print all possible strings created from that. The mapping of the numbers is the one as exactly on a phone s keypad. i.e. for 1,0-> No Letter for 2->...

typedef ing STL wstring

Why is it when i do the following i get errors when relating to with wchar_t? namespace Foo { typedef std::wstring String; } Now i declare all my strings as Foo::String through out the program, ...

C# Marshal / Pinvoke CBitmap?

I cannot figure out how to marshal a C++ CBitmap to a C# Bitmap or Image class. My import looks like this: [DllImport(@"test.dll", CharSet = CharSet.Unicode)] public static extern IntPtr ...

Window iconification status via Xlib

Is it possible to check with the means of pure X11/Xlib only whether the given window is iconified/minimized, and, if it is, how?

热门标签