-1

这是要点。我有一个带有字符串的结构,它有一个可以调用结构中信息的向量。我想创建一个我可以引用的文件,但为了做到这一点,我需要一个具有字符的结构,具有设定的大小,我不能只是将原始结构切换到字符。这就是我所拥有的:

struct PERSON
{
    string fName;
    string lName;
    string Address;
};

struct tmpPERSON
{
    char fName2[50];
    char lName2[50];
    char Address2[50];
};

class addressBook
{
private:
    vector<PERSON> people;
};

我需要能够将存储的信息从我的人员向量复制到我的 tmpPERSON 结构中。任何人都知道如何做到这一点,因为我只是迷路了。

4

1 回答 1

0

像这样:

for (vector<PERSON>::iterator iter = people.begin(), end = people.end(); iter != end; ++iter)
{
    tmpPERSON tmp;

    strncpy(tmp.fName, iter->fName.c_str(), 50);
    strncpy(tmp.lName, iter->lName.c_str(), 50);
    strncpy(tmp.Address, iter->Address.c_str(), 50);

    // use tmp as needed...
}
于 2013-04-04T20:52:42.367 回答