- android - 多次调用 OnPrimaryClipChangedListener
- android - 无法更新 RecyclerView 中的 TextView 字段
- android.database.CursorIndexOutOfBoundsException : Index 0 requested, 光标大小为 0
- android - 使用 AppCompat 时,我们是否需要明确指定其 UI 组件(Spinner、EditText)颜色
#include <iostream>
using namespace std;
int main()
{
struct list
{
char name[20];
int age;
double height;
list *next;
};
list *first, *temp, *temp2, *newlist1;
first->next = temp;
temp->next = temp2;
newlist1 = new list;
newlist1->name = "Steve";
newlist1->age = 23;
newlist1->height = 2.3;
newlist1->next = temp2;
temp->next = newlist1;
newlist1->next = temp2;
temp->next = newlist1;
temp2 = newlist1->next;
temp2->next = newlist1->next;
delete temp2;
cout << " Name is: " << newlist1->name << " ";
cout << " Age is: " << newlist1->age << " ";
cout << " Height is: " << newlist1->height;
}
这是将名称值分配给节点的方式吗? ...我试过 strcpy 但它一直说 strcpy 未声明...或其他内容。有人可以告诉我如何将 name[20] char 类型分配到节点上的代码吗?我真的有这个问题:(
最佳答案
strcpy 是标准 C 库的一部分。它的函数声明需要#included 以便编译器知道它是什么。尝试添加 #include <cstring>
在文件的开头。
但是,由于您使用的是 C++,我真正的建议是切换到使用 C++ 标准字符串类。使用它更容易、更安全,也更像 C++……为了使用它,#include <string
> 然后将您的声明更改为 std::string name;
您很快会遇到的另一个问题是您只分配了 1 个列表对象 (newlist1),但正在引用,例如 first->next
什么时候first
未初始化。
关于c++ - 如何为节点分配名称?我在这里遗漏了什么吗?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5201491/
我正在尝试运行某人给我的一些 C++ 代码。起初有一个指向 istream 文件的断开链接,我通过添加包含路径修复了这个问题: C:\Program Files (x86)\Embarcadero\R
谁能告诉我如何防止 .git 目录的内容被上传到 PyPi。我的 MANIFEST.in 看起来像这样: global-include *.py *.js *.rst *.html *.css *.l
最近在 typescript 项目的VSCode中遇到如下情况: 文件:some-interface.ts // no import statements have been skipped. Thi
为我找到这个问题的合适标题有点困难,所以也许这个例子会澄清我的问题。 我正在发出 ajax 请求以将一些变量从 JS 传递到 PHP。这些变量之一是带有一些选项的 URL,即 https://www.
我是一名优秀的程序员,十分优秀!