c++ - String in struct -


#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

Popular posts from this blog

How to provide Authorization & Authentication using Asp.net, C#? -

toolbar - How to add link to user registration inside toobar in admin joomla 3 custom component -

How to use Authorization & Authentication in Asp.net, C#? -