小编aks*_*007的帖子

结构体中的字符串

#include <bits/stdc++.h>

using namespace std;

struct node
{
    std::string a;
};

int main()
{
    cout << str << endl;
    struct node* p = (struct node*)(malloc(sizeof(struct node)));
    p->a = "a";
    cout << p->a;
    return 0;
}
Run Code Online (Sandbox Code Playgroud)

上面的代码产生运行时错误。该结构适用于整数,但是当我尝试使用字符串作为其成员变量时,会发生错误。它还会在代码cheide上给出运行时错误。

c++ string struct

1
推荐指数
2
解决办法
1万
查看次数

标签 统计

c++ ×1

string ×1

struct ×1