I need to write a tree, with nodes being strings (that is important, because I need some string class standard functions).
But when I try to implement my code, everything breaks on the earliest stage:
#include <iostream>
#include <string>
using namespace std;
struct test {
string str;
struct test * r, * l;
};
int main() {
struct test* node = (struct test*)malloc(sizeof(struct test));
node->str = "abc";
cout << node->str;
return 0;
}
My Visual Studio throws Access violation reading location at me. What frustrates me more is that for int instead of string everything works just fine. So, I need just to be able to use string as a struct member, and to be able to code trees with that struct.