c++ - String in struct -
this question has answer here:
#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; } the above code produces runtime error. struct working ints when try use string member variable, error occurs. gives runtime error on codechef ide.
c++ not c.
you shouldn't #include bits folder.
you should not use malloc allocate memory. should use new instead:
node* p = new node(); or don't dynamically allocate memory @ all:
node p; c++ not c.
Comments
Post a Comment