I am A needy little idiot

The Partridge Family were neither partridges nor a family. Discuss.
Post Reply
User avatar
Alacaster
Posts: 81
Joined: October 16th, 2016, 5:08 pm
Location: Spokane, WA

I am A needy little idiot

Post by Alacaster » April 5th, 2017, 2:50 am

If I wanted to define a variable type that was an array of multiple character arrays like for an inventory or a list of words or sentences.
Could you use a struct?
like

list Inventory[4]

and it would have four 20 byte strings 0, 1, 2, and 3

Really, I want to make my own custom variable that I can put in a header file.
If this is too complicated of a question just ignore me and my ignorant little unworthy self.
Also do you have any good suggestions for C++ Programming books.
Last edited by Alacaster on April 8th, 2017, 12:01 am, edited 1 time in total.
You can't be betrayed if you don't have any friends.
Why live? Cause why not.

albinopapa
Posts: 4373
Joined: February 28th, 2013, 3:23 am
Location: Oklahoma, United States

Re: I am A needy little idiot

Post by albinopapa » April 5th, 2017, 4:50 am

Code: Select all

struct Inventory
{
     char item_name[20]
};

Inventory items[4]
Something like this would let the compiler know the size of the Inventory struct at compile time, which is perfect for serializing ( saving to disk ) since all the memory is contiguous.

As long as your arrays inside the struct are defined as static arrays like it is here, you can store the struct with a single write command.

Code: Select all

#include <fstream>
std::ofstream file("inventorylist.inv", std::ios::binary);
file.write(reinterpret_cast<char*>( items ), sizeof(Inventory) * 4 );
file.close();
However, if your struct just has heap allocated pointers or something like std::string, then you will have to have a write command for each element in the struct in the order that you want them in because the data is not in the same memory address range as the Inventory object itself.



As for the book thing, don't have any suggestions. There are a crap ton of resources online that you can read through and learn the ins and outs of C++.

cplusplus.com and
cppreference.com

are just two of the ones I use. I know cplusplus.com has a tutorials series that you can go through, plus lots of examples on how to use everything in the Standard Template Library, plus a forum where people have asked questions and have had them answered. It's like an all in one package.
If you think paging some data from disk into RAM is slow, try paging it into a simian cerebrum over a pair of optical nerves. - gameprogrammingpatterns.com

User avatar
Alacaster
Posts: 81
Joined: October 16th, 2016, 5:08 pm
Location: Spokane, WA

Re: I am A needy little idiot

Post by Alacaster » April 5th, 2017, 11:17 pm

Thanks
You can't be betrayed if you don't have any friends.
Why live? Cause why not.

albinopapa
Posts: 4373
Joined: February 28th, 2013, 3:23 am
Location: Oklahoma, United States

Re: I am A needy little idiot

Post by albinopapa » April 6th, 2017, 12:11 am

Was wondering if that is what you wanted by your description, glad it helped.
If you think paging some data from disk into RAM is slow, try paging it into a simian cerebrum over a pair of optical nerves. - gameprogrammingpatterns.com

User avatar
chili
Site Admin
Posts: 3948
Joined: December 31st, 2011, 4:53 pm
Location: Japan
Contact:

Re: I am A needy little idiot

Post by chili » April 6th, 2017, 1:20 am

As for books, I have never read them, but a good intro seems to be C++ Primer, and a good in-depth look would be Bjarne's book.
Chili

Byteraver
Posts: 60
Joined: May 19th, 2016, 6:48 am
Location: Belgium, Europe

Re: I am A needy little idiot

Post by Byteraver » April 6th, 2017, 9:12 pm

Hi

Concerning books, I really liked the C++ books from Herbert Schildt, he explains in a very clear style in my opinion (just c++ though, no windows / graphics programming and only C98c98):
https://images-na.ssl-images-amazon.com ... SV6NQL.jpg

The book(s) by Peter Walsh are not bad either (DirectX 10, maybe there's a newer version now):
https://images-na.ssl-images-amazon.com ... 3,200_.jpg
Last edited by Byteraver on April 7th, 2017, 7:34 pm, edited 1 time in total.

simonjoel
Posts: 1
Joined: April 7th, 2017, 8:33 am

Re: I am A needy little idiot

Post by simonjoel » April 7th, 2017, 9:16 am

chili wrote:As for books, I have never read them, but a good intro seems to be C++ Primer, and a good in-depth look would be Bjarne's book.
do you have any recommendation for Directx game develop books, I mean, some book to read after the C++ primer and more about game develop.

Post Reply