gpt4 book ai didi

c++ - 从循环添加到结构 (c++)

转载 作者:行者123 更新时间:2023-11-27 22:58:11 26 4
gpt4 key购买 nike

所以我正在使用下面的代码,但在尝试从结构中的一行调用文本时遇到错误。

struct lines
{
LPCSTR text;
int mInt;
};


for (int n = 0; n < lineCount - 1; ++n) {
vector<lines> sub;
lines lineData;
LPCSTR onlinePlayerName = (LPCSTR)PLAYER::GET_PLAYER_NAME((Player)(n));
int onlinePlayerPed = PLAYER::GET_PLAYER_PED(n);

//lines(n) = struct( onlinePlayerName, onlinePlayerPed );
sub.push_back(lines());
lineData.text = onlinePlayerName;
lineData.mInt = onlinePlayerPed;
//add struct to struct list
sub.push_back(lineData);
}

但是当我尝试从 lines 调用时

lines[i].text

我收到“错误:不允许类型名称”。

最佳答案

这里的问题是您在类型上使用了 [] 运算符。您将行声明为 struct。(这有助于为您的 typenames 提供一个大写字母,这样您就可以更容易地区分它们。)我想你是想调用 sub[i].text

关于c++ - 从循环添加到结构 (c++),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30493361/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com