can anyone point me in the right direction

when i compile my code it runs fine. but when i try to add a word or print the word list it goes crazy and breaks..


main
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
int main()
{
string line;
int choice;
string word;
menu myMenu;


fstream filestr;

filestr.open ("wordsList.txt", fstream::in | fstream::out | fstream::app);


 

 do
 {


 mainMenu();
 cin >> choice;
 cin.ignore();

  if (choice == 2)
  {
	  editMenu();
	  cin >> choice;
	  cin.ignore();

	  switch (choice)
	  {
		  case 5:
			  cout << "\nPlease type in the word to be added\n" << endl;
			  myMenu.addWord();
			  break;
			  

		  case 6:
			  cout << "\nPlease enter the word to be deleted\n" << endl;
			  cin >> word;
			  break;

		  case 7:
			  cout << "\nPlease enter the word you wish to search for\n" << endl;
			  cin >> word;
			  break;

		  case 8:
			  cout << "\nYou have chosen to print the words list\n\n" << endl;
			  myMenu.printWordList();
			  break;

		  case 9:
			  break;
		 
			  
		  default:
			  cerr << "You have entered an Invalid choice\n" << endl;
	  }

 filestr.close();

 system("pause");
	return 0;
}

h file
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
#include <iostream>
using namespace std;

class menu
{
public:

	
	string deleteWord();
	string addWord();
	string searchWords();
    string printWordList();

private:
	string wordList;


};

cpp file
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
#include <iostream>
#include <iomanip>
#include <string>
#include "menu.h"
#include <fstream>
#include "play.h"


using namespace std;

string word;
fstream filestr;
string line;

string menu::addWord()
{
fstream filestr;

filestr.open ("wordsList.txt", fstream::in | fstream::out | fstream::app);
			  cin >> word;	
			  filestr << word <<endl;
			   return 0;

}

string menu::printWordList()
{
fstream filestr;

filestr.open ("wordsList.txt", fstream::in | fstream::out | fstream::app);

	if (filestr.is_open())
			  {
				  while (filestr.good())
				  {
					  getline (filestr, line);
					  cout << line << endl;
				  }
				  
			  }
			  else cout << "Unable to open file " << endl;
			  return 0;
}
There is too much missing from this for me to make any sense of it, and what is here has numerous errors (even though some of those may be because there is stuff missing). If you still need help I would suggest posting all of the code in a compilable state.
here is the whole code

main.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
#include <iostream>
#include <iomanip>
#include <string>
#include "menu.h"
#include <fstream>
#include "play.h"

using namespace std;






void playMenu()
{
	cout << "\n\nPlease select your Choice" << endl; // play menu
	cout << "5. Play Game " << endl;
	cout << "9. Go Back" << endl;
}

void editMenu()
{
	cout << "\n\nPlease Enter Your Choice Below." << endl; // edit words list menu
	cout << "*******************************" << endl;
	cout << "5. Add a Word" << endl;
	cout << "6. Delete a Word" << endl;
	cout << "7. Search for a Word" << endl;
	cout << "8. Print Word List" << endl;
	cout << "9. Go Back" << endl;
}
	

void mainMenu()
{
	cout << "\n\nPlease Enter Your Choice Below." << endl; // main menu choices
	cout << "*******************************" << endl;
	cout << "1. Play Game" << endl;
	cout << "2. Edit Words List" << endl;
	cout << "3. Show Hangman Galley" << endl;
	cout << "4 Quit" << endl;
}


int main()
{
string line;
int choice;
string word;
menu myMenu;


std::fstream filestr;

filestr.open ("wordsList.txt", std::fstream::in | std::fstream::out | std::fstream::app);



 

 do
 {


 mainMenu();
 cin >> choice;
 cin.ignore();

  if (choice == 2)
  {
	  editMenu();
	  cin >> choice;
	  cin.ignore();

	  switch (choice)
	  {
		  case 5:
			  cout << "\nPlease type in the word to be added\n" << endl;
			  myMenu.addWord(word);
			  break;
			  

		  case 6:
			  cout << "\nPlease enter the word to be deleted\n" << endl;
			  cin >> word;
			  break;

		  case 7:
			  cout << "\nPlease enter the word you wish to search for\n" << endl;
			  cin >> word;
			  break;

		  case 8:
			  cout << "\nYou have chosen to print the words list\n\n" << endl;
			  myMenu.printWordList();
			  break;

		  case 9:
			  break;
		 
			  
		  default:
			  cerr << "You have entered an Invalid choice\n" << endl;
	  }



		 
  }
	  else if (choice == 3)
	  {
		  hangGallery();// won't be in the final. just holding it here because it took me a while to draw them perfectly and a i am saving them here for when i need them
		  
		  break;
  }
	  else if (choice == 1)
	  {
		  playMenu();
		  cin >> choice;
		  cin.ignore();

		  switch (choice)
		  {
		  case 5:
			  cout << " You have chosen to set your difficulty to easy and play\n" << endl;
			  break;

		  case 6:
			   cout << " You have chosen to set your difficulty to hard and play\n" << endl;
			  break;

		  case 7:
			  cout << "show the easy words list\n" << endl;
			 break;

		  case 8:
			  cout << "show the hard words list\n" << endl;
			  break;

		  case 9:
			
			  break;
		  

		  default:
			  cerr << "You have entered an Invalid choice\n" << endl;

		  }
	  }
	  else if (choice == 4)
	  {
		  cout << "\nHAVE A NICE DAY\n" << endl;
	  }
  
 
 }while (choice != 4);



 system("pause");
	return 0;
}

menu.cpp file
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
#include <iostream>
#include <iomanip>
#include <string>
#include "menu.h"
#include <fstream>
#include "play.h"


using namespace std;

string word;
std::fstream filestr;
string line;

string menu::addWord(string word)
{
std::fstream filestr;

filestr.open ("wordsList.txt", std::fstream::in | std::fstream::out | std::fstream::app);
			  cin >> word;	
			  filestr << word <<endl;
			   filestr.close();
			   return 0;

}

string menu::printWordList()
{
std::fstream filestr;

filestr.open ("wordsList.txt", std::fstream::in | std::fstream::out | std::fstream::app);

	if (filestr.is_open())
			  {
				  while (filestr.good())
				  {
					  getline (filestr, line);
					  cout << line << endl;
				  }
				  
			  }
			  else cout << "Unable to open file " << endl;
			   filestr.close();
			  return 0;
}

menu.h file
1
2
3
4
5
6
7
8
9
10
11
12
13
14
#include <iostream>
#include "menu.h"
using namespace std;

class play: public menu
{
public:

	play();

	void setDifficulty() const;
	void printEasyList() const;
	void printhardList() const;
};
Topic archived. No new replies allowed.