hangman game

in visual studio, im trying to make a hangman game that selects a random word from a file. on compiling, it gives the error: "error C3867: 'std::basic_string<char,std::char_traits<char>,std::allocator<char>>::length': function call missing argument list; use '&std::basic_string<char,std::char_traits<char>,std::allocator<char>>::length' to create a pointer to member c:\users\...\main.cpp"
can anyone tell me what im doing wrong? thanks.




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

#include <iostream>
#include <cstdlib>
#include <fstream>
#include <ctime>
#include <string>
using namespace std;
//hangman
/*
display area
pick word randomly
ask for input
handle input
display new area
prompt user again
handle drawing
handle win
handle loss


*/


//prototyping----------------------
void startScreen(int wordsize);
void pickWord();


//let choose color of text

int main()
{
	system("cls");
	string choice;

	cout << "Hello. enter 'play' to play a new game" << endl;
	cin >> choice;
	if (choice == "PLAY" || choice == "Play" || choice == "play")
	{
		pickWord();

	}
	else
	{
		cout << "what..?" << endl;
		main();
	}






	system("pause");
}




void startScreen(int wordsize)
{
	

	cout <<" ________" << endl;
	cout << "|       |" << endl;
	cout << "|       |" << endl;
	cout << "|" << endl;
	cout << "|" << endl;
	cout << "|" << endl;
	cout << "|" << endl;
	cout << "|" << endl;

	
	

	cout << wordsize << endl;
	
}






void pickWord()
{
	//open dictionary file
	ifstream dictionary;
	dictionary.open("dictionary.txt");
	

	//check for error
	if (dictionary.fail())
	{
		cerr <<"Failure loading dictionary." << endl;
		system("pause");
		exit(0);
	}


	//pick random word from dictionary------------------------------
	srand(time(0));
	string word[8000];
	cout << "loading dictionary...\n";
	for (int i = 0; i < 8000; i++)
	{
		dictionary >> word[i];
	}
	


	int choice=1 + (rand() % 8000);
	string chosenWord = word[choice];



	int wdsz=chosenWord.length;

	startScreen(wdsz);
}


int wdsz=chosenWord.length; You need to put empty brackets on end of length () to call the function.
oh my god thats so obvious. k thanks haha
Topic archived. No new replies allowed.