#include <iostream>
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
#include <algorithm>
#include <vector>
#include <string>
#include <map>
#include <sstream>
#include <string.h>
using namespace std;
struct node {
string s;
int a;
};
int main()
{
int i, j, k;
string s;
struct node *st, t;
st = ( struct node * )malloc( sizeof( struct node ) );
st->a = 2;
st->s = "SDAD";
return 0;
}
it gives segmentation fault due to st->s = "SDAD". why ?
edit : using new instead of malloc, it worked fine.