I've recently made a short a program about a new lesson that I've learned online about programming(which I'm a beginner in)C++, which I do every time I learn a new concept, to be in-depth with the concept of it and it's uses.(Its how I teach myself in programming). I used vector in my program and it solved my problem. But, it created a new one.
(You might have already seen this code)
#include <iostream>
#include <string>
#include <windows.h>
#include <vector>
using namespace std;
int main()
{
string LetterInput, LetterLoad, input;
string Words[5] = {"fire","eggs","roll","camera","lotion"};
vector <string> PossibleAnswers;
int Number,a = 0;
int Size,Num;
cout << "Lets play HANGMAN! " << endl;
Sleep(500);
cout << "Think of a word and type in the number" << endl;
cout << "of letters there are" << endl;
cin >> Size;
for (int i = 0; i <= Size; i++){
LetterLoad += "_";
}
Num = sizeof(Words)/sizeof(string);
for (int i = 0; i <= Num ; i++){
if ((unsigned)Size == Words[i].size()){
PossibleAnswers.push_back(Words[i]);
}
}
for (int i = 0;i <= Num;i++){
cout << PossibleAnswers[i] << endl;
}
cout << "Okay lets start" << endl;
Sleep(750);
while(a == 0)
{
cout << PossibleAnswers[0] << endl;
cout << PossibleAnswers[1] << endl;
cout << LetterLoad << endl;
cout << "Type in the position of the letter you want to guess" << endl;
cin >> Number;
cout << "What letter do you want to put?" << endl;
cin >> LetterInput;
LetterLoad[Number-1] = LetterInput[0];
for (size_t i = 0; i <= PossibleAnswers.size(); i++){
for (int n = 0; n <= Size; n++){
if (LetterInput[n] == PossibleAnswers[i][n]){
cout << "Got one" << endl;
}
}
}
}
return 0;
}
The program was able to take the right words. But, it stops working when it is about to reach the cout << "Okay lets start" << endl;
and then everything below that line of code. I have heard that vectors require "memory allocation" from other people. Does that have something to with the program not running properly? and how do I fix it?