printing shapes in hangman

im using a file to print shapes for hangman and im passing my shapes as an array how would i do that?
would i need to fill the shape info
shapes[]={}
Do you know file input/output yet? Look into ifstream and ofstream:
http://www.cplusplus.com/reference/fstream/ifstream/
http://www.cplusplus.com/reference/fstream/ofstream/

For spacing and fill: setw and setfill: http://www.cplusplus.com/reference/iomanip/

Need to read whitespace as data:
http://stackoverflow.com/questions/6774825/reading-from-ifstream-wont-read-whitespace

Could you pastebin one of the "shapes" so we can see what we're dealing with?
Do you have any code started yet?
Last edited on
yes i do and i have the code and im using ifstream
im trying to to fix so it shows in my playgame function

[output
\-\-\-\-\
\-\-\
\-\
output]
Ok, so show us a bit of code for that function at least. Can't help without seeing what you've done so far.

I'm not seeing how your output above relates to a hangman game... is it the number of letters in the word?

EDIT:
For your original question, if you know the longest line that you'll ever encounter, then a char array can be initialized as one char longer than that number. Otherwise you will need to look into dynamic memory (such as using the keyword 'new' to allocate memory on the heap and delete to release it).

While it's a good idea from a developer standpoint to know how to use new and delete properly, there are some C++ standard libraries that simplify matters considerably. The String library (<string> not <string.h>) is an example of a c++ object that can grow as needed, vector is used if you need something other than characters. There are many more container classes also designed to grow as needed, but those are the most commonly used.

There are a lot of examples out there with a quick google, so I won't go into detail, but I think you'll have the easiest time with the <string> library.
Last edited on
Topic archived. No new replies allowed.