How similar is an std::vector to a raw array in C++? -


I'm writing a hangman game. I have argued and failed, both with myself and my game logic The four estimates (the person estimated in the letter) are not being added to the correct memory slot of vector estimate array. Assume that the word is an input word by the user I

I think this would work if the guess was a raw array, is there any reason why it is not working with vector?

  / Suppose that the number of attempts left zero coutWord (int try, std :: string words, four estimates) {std :: vector & lt; Four & gt; GuessArray (word.length ()); // This estimate is supposed to be linked to projected area estimates; //this. For (int i = 0; i & lt; word.length (); i ++) {if (estimate == word [i]) {guessArray [i] = estimate; Std :: cout & lt; & Lt; "" & Lt; & Lt; Estimates [i] & lt; & Lt; ""; to continue; } Std :: cout & lt; & Lt; "_"; } Std :: cout & lt; & Lt; Std :: endl & lt; & Lt; Std :: endl; }  

EDIT: With this code, my aim is to crush all the uninformed places and also have estimated spaces for the loop. I just need to "remember" the past memories so that I can get the right output. Given word = "appletsus":

  Input: aa _ _ _ _ _ _ _ _ _ _ Input: papp_ _ _ _ _ _ _  

e.t.c.

A vector can be indexed with subscript notation [] , And this is an STL container stored in compatible memory, like an array, you can have any type of any kind.

A vector automatically resizes the shape. An array is 'statically' shaped, and it can not be easily resized (with the exception of the manual function called Rialoch). You can use the push_back function to handle it, and you can To save time before reallocation.

An array does not track its size, while a vector has functions that can see it.

If you are unsure of the shape of the vector, then just go ahead and use it. Push_back () to automatically add items to handle shaping case. If you reserve a part of the memory through resizing () and after that index it is easy to use as the array, but you lose some synthetic benefits of using it as a dynamic-size object Are there.


Comments

Popular posts from this blog

python - Overriding the save method in Django ModelForm -

html - CSS autoheight, but fit content to height of div -

qt - How to prevent QAudioInput from automatically boosting the master volume to 100%? -