【发布时间】:2021-06-25 05:42:35
【问题描述】:
#include <iostream>
#include <list>
#include <string.h>
struct message
{
int id;
char mesg[100];
};
int main()
{
struct message Msg;
Msg.id=111;
strcpy(Msg.mesg," am fine");
list<Msg*> l1;
}
我需要这个l1 列表大小不为空。但是当我编译这段代码时,它显示了一个错误。
【问题讨论】:
-
list<Msg *> l1;==>std::list<Msg *> l1; -
你好先生/女士,实际上我需要 l1.size() 值不为空,但如果我运行此代码意味着我只显示为空
-
@mohan 列表是空的,因为你没有在列表中放入任何值,例如使用它的
push_back()方法,例如:l1.push_back(&Msg); -
无关:您在 C++ 中使用 C 字符串是否有原因?
Msg.mesg = " am fine";怎么了? -
no.. 用于插入值,正在使用 C 字符串
标签: c++ list dictionary vector stl