I'm trying to create a simple linked list and a variable t oread through it. However, I'm gettin a segfault in a place I didn't think would get one. Here's my code
#include <iostream>
#include <string>
using namespace std;
struct Node {
string name;
Node *next;
};
int main() {
Node *one;
one->name = "one";
Node *two;
two->name = "two";
Node *three;
three->name = "three";
Node *reader = one;
while (reader != NULL) {
cout << reader->name << endl;
reader = reader->next;
}
}
I added a few cout's around my code and realized that the segfault was happening after
one->name = "one";
I'm not very experienced in C++, but I thought a segfault occurred when the stacks overflowed in memory. I don't see how the program should be running out of memory there. I'd appreciate any help in finding out the problem. Thanks.