call to a member function

what am i doing wrong here. i cannot get my program to call a member function.

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
  if (choice == 2)
  {
	  editMenu();
	  cin >> choice;
	  cin.ignore();

	  switch (choice)
	  {
		  case 5:
			  cout << "\nPlease type in the word to be added\n" << endl;
			  menu.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;
			  menu.printWordList();
			  break;

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

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
sing 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;
			   filestr.close();
			  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;
				  }
				  filestr.close();
			  }
			  else cout << "Unable to open file " << endl;
			  return 0;
}
You have to create an object :

1
2
3
menu my_menu;
// ...
my_menu.addWord();


http://www.cplusplus.com/doc/tutorial/classes
Topic archived. No new replies allowed.