#include <iostream> #include <conio.h> #include <vector> #include <stdio.h> using namespace std; struct treem { char node[5]; char parent[5]; int number; }; vector <treem> CreateAtree() { char value[5]; char parn[5]; int num; vector<treem> tree; treem g; printf("Input the name of the root\n"); scanf("%s",&value); printf("Input the value of node\n"); scanf("%d", &num); tree.push_back(g); strcpy(tree.at(0).parent,"NO"); strcpy(tree.at(0).node, value); tree.at(0).number = num; int i = 1; int flag = 0; while (num != 0 && parn[0] != '0') { printf("Input the name of node\n"); scanf("%s",&value); printf("Input the parent of node\n"); scanf("%s",&parn); printf("Input the value of node\n"); scanf("%d",&num); for (vector<treem>::iterator it = tree.begin(); it != tree.end(); it++) { if (strcmp(parn, it->node) == 0) flag = 1; if (flag == 1) { tree.push_back(g); strcpy(tree.at(i).parent, parn); strcpy(tree.at(i).node, value); tree.at(i).number = num; i++; flag = 0; } else printf("There is not such parent,please try again\n"); } } return tree; } int main() { vector<treem> tree = CreateAtree(); _getch(); return 0; } I do something like a tree. I create a root then when I add a new vertex and indicate the root (my verification is there) knocks out the message vector iterator not incrementable. I work with vector for the first time therefore I ask for advice how to fix it.