String assignment segmentation fault (core dump)
Please solve this issue, you can run this program.. its complete
Code:
#include<iostream>
#include<cstdlib>
#include<string>
using namespace std;
struct node
{
string name;
int i;
};
int main(int argc, char *argv[])
{
struct node *first;
first = (struct node *) malloc(sizeof(struct node));
first->name ="Hi there";
cout << first->i;
}
How to use new in this context?
Can you tell me the exact code to use the new for this?
and make me clear why this is throwing segmentation fault(core dump)?
I don't this this is happening for malloc?
structure use in C++ good practice?
Is it good practice to use in c++? or there is a better way let me know, actually I am good in c but may be intermediate in c++, most of the time I cant find the diffrence between them and so I use c codes, how to know more using c++ features and diffrentiate between the c++ and C coding, I would also appreciate the notion of good coding practice in c++
didn't get the precise answer
Is it good to use structure in C++?
and how to use new here in my code to make it work?
just make the necessary changes and post the code, thanks in advance.