så länge ni har ett program att kompilera detta med så skall det gå att köra gubbe och lägga till nya ord ^^<br /><br />kod:<br />[code]<br />#include &lt;iostream&gt;<br />#include &lt;string&gt;<br />#include &lt;vector&gt;<br />#include &lt;fstream&gt;	// Files<br />#include &lt;iomanip&gt;	//setfill setw etc..<br />#include &lt;climits&gt;	//numeric limits etc...<br />#include &lt;ctime&gt;<br />#include &lt;cstdlib&gt;<br /><br />typedef std::vector&lt;std::string&gt;&amp; hangmanWordsVector;<br /><br />int menu();<br />void ReadHangman(hangmanWordsVector hangmanwords);<br />void Write(hangmanWordsVector hangmanwords);<br />void Play(hangmanWordsVector hangmanwords);<br />void makeLowerCase(std::string&amp; makeLow);<br />void makeUnderscore(std::string&amp; change);<br />void win(std::string unknownWord);<br />void Lost(std::string unknownWord);<br />int RandomWord(int maxValue);<br /><br /><br />enum MenuChoice<br />{<br />	WriteHangman = 1,<br />	PlayHangman,<br />	RulesHangman,<br />	ShowWords<br /><br />};<br /><br />int main (int argc, char** argv)<br />{<br />	std::vector&lt;std::string&gt; hangmanwords;<br />	int menuChoise = 0;<br /><br />	std::cout &lt;&lt; &quot;Hello you&#039;ve come to a game of Hangman\n&quot;;<br /><br />	while ( (menuChoise = menu()) &gt; 0)<br />	{<br />		switch(menuChoise)<br />		{<br />		case WriteHangman:<br />			Write(hangmanwords);<br />			break;<br />		case PlayHangman:<br />			Play(hangmanwords);<br />			break;<br />		case RulesHangman:<br />			{<br />				std::cout &lt;&lt; &quot;\nThe rules are simple:\n\n&quot;;<br />				std::cout &lt;&lt; &quot;1. You will guess letters that you think will be in the word\n&quot;;<br />				std::cout &lt;&lt; &quot;2. If you guess a letter that isnt in the word you will loose a chanse\n&quot;;<br />				std::cout &lt;&lt; &quot;3. If you guess the right word you will have won\n\n&quot;;<br />			}<br />			break;<br />		case ShowWords:<br />			{<br />				ReadHangman(hangmanwords);<br />				int check = hangmanwords.size();<br />				for (int i = 0; i &lt; check; i++)<br />				{<br />					std::cout &lt;&lt; hangmanwords[i] &lt;&lt; std::endl;<br />				}<br /><br />			}<br />			break;<br />		default:<br />			std::cout &lt;&lt; &quot;\nInvalid choice&quot;; <br />		}<br />	}<br />	return 0;<br />}<br /><br />int menu()<br />{<br />	int choise = 0;<br /><br />	std::cout &lt;&lt; std::setfill(&#039;/&#039;) &lt;&lt; std::setw(11) &lt;&lt; &quot;/\n&quot;;<br />	std::cout &lt;&lt; WriteHangman &lt;&lt; &quot;.\tAdd a word\n&quot;;<br />	std::cout &lt;&lt; PlayHangman &lt;&lt; &quot;.\tPlay the game\n&quot;;<br />	std::cout &lt;&lt; RulesHangman &lt;&lt; &quot;.\tRead the rules\n&quot;;<br />	std::cout &lt;&lt; &quot;0.\tQuit\n&quot;;<br />	std::cin &gt;&gt; choise;<br /><br />	return choise;<br />}<br /><br />void Write(hangmanWordsVector hangmanwords)<br />{<br />	ReadHangman(hangmanwords);<br />	std::string word;<br /><br />	std::cout &lt;&lt; &quot;Please write the word you want to add\n&quot;;<br />	std::cin &gt;&gt; std::ws;<br />	std::getline(std::cin, word);<br /><br />	makeLowerCase(word);<br /><br />	hangmanwords.push_back(word);<br /><br />	std::ofstream file;<br /><br />	file.open(&quot;words.txt&quot;);<br /><br />	for(int i = 0; i != hangmanwords.size(); i++)<br />	{<br />		file &lt;&lt; hangmanwords[i] &lt;&lt; std::endl;<br />	}<br /><br />	file.close();<br />}<br /><br />void Play(hangmanWordsVector hangmanwords)<br />{<br />	ReadHangman(hangmanwords);<br /><br />	srand (static_cast &lt;int&gt;(time(NULL)));<br /><br />	int guessesLeft = 10;<br /><br />	std::string unknownWord;<br />	std::string guess;<br />	std::string wordUnderscore;<br /><br />	int randomIndex = RandomWord(hangmanwords.size());<br />	unknownWord = hangmanwords[randomIndex];<br />	wordUnderscore = unknownWord;<br />	makeUnderscore(wordUnderscore);<br /><br />	std::cin.ignore(2,&#039;\n&#039;);<br /><br />	size_t found = 0;<br /><br />	while(guessesLeft &gt; 0)<br />	{<br />		std::cout &lt;&lt; wordUnderscore &lt;&lt; std::endl;<br />		std::cout &lt;&lt; &quot;Guess a letter: &quot;;<br />		std::getline(std::cin, guess);<br />		bool search = true;<br />		std::vector&lt;int&gt; positionList;<br /><br />		found = unknownWord.find(guess);<br /><br />		int size = unknownWord.size();<br />		int position = found;<br /><br />		if(found != std::string::npos)<br />		{<br />			while((position = unknownWord.find(guess,position)) != std::string::npos)<br />			{<br />				positionList.push_back(position);<br />				position++;<br />			}<br />			<br />			for(unsigned int j = 0; j &lt; positionList.size(); j++)<br />			{<br />				wordUnderscore[positionList[j]] = unknownWord[positionList[j]];<br />			}<br />			if(wordUnderscore == unknownWord)<br />			{<br />				win(unknownWord);<br />				break;<br />			}<br />		}<br />		else<br />		{<br />			guessesLeft--;<br />			std::cout &lt;&lt; &quot;You have &quot; &lt;&lt; guessesLeft &lt;&lt; &quot; guesses left&quot; &lt;&lt; std::endl;<br />		}<br />		if (guessesLeft == 0)<br />		{<br />			Lost(unknownWord);<br />		}<br />	}<br />}<br /><br />void ReadHangman(hangmanWordsVector hangmanwords)<br />{<br />	std::ifstream file(&quot;words.txt&quot;);<br />	if (!file.is_open())<br />	{<br />		std::cout &lt;&lt; &quot;Error: File \&quot;words.txt\&quot; could not be opened!&quot;;<br />		std::cout &lt;&lt; &quot;\nIf this is the first time you&#039;ve run the program it will be created!&quot; &lt;&lt; std::endl &lt;&lt; std::endl;<br />		return;<br />	}<br /><br />	if(!hangmanwords.empty())<br />	{<br />		hangmanwords.clear();<br />	}<br /><br />	std::string word;<br /><br />	while(!file.eof())<br />	{<br />		std::getline(file, word);<br />		if (word.empty()) {continue;}<br /><br />		hangmanwords.push_back(word);<br />	}<br />}<br /><br />void makeLowerCase(std::string&amp; makeLow)<br />{<br />	for (unsigned int i = 0; i &lt; makeLow.size(); i++)<br />	{<br />		makeLow[i] = tolower(makeLow[i]);<br />	}<br />}<br /><br />int RandomWord(int maxValue)<br />{<br />	return rand() % maxValue;<br />}<br /><br />void makeUnderscore(std::string&amp; change)<br />{<br />	int underscore = change.size();<br /><br />	for (int i = 0; i &lt; underscore; i++)<br />	{<br />		change[i] = &#039;_&#039;;<br />	}<br />}<br /><br />void win(std::string unknownWord)<br />{<br />	std::cout &lt;&lt; &quot;Congratiolations you found the word!\nAnd the word was: &quot; &lt;&lt; unknownWord &lt;&lt; &quot;\n\n\n\n\n&quot;;<br />}<br /><br />void Lost(std::string unknownWord)<br />{<br />	std::cout &lt;&lt; &quot;The word was: &quot; &lt;&lt; unknownWord &lt;&lt; std::endl;<br />}<br />[/code]