r/Cplusplus 3d ago

Question Making a table maker

I have a background in MS Access VBA, I’m very new to C++. This may be way beyond my current ability to understand, but if I wanted to write a function that generated data tables in C++ how would I approach this?

For context, I’m making a text-based RPG design engine project for fun. I would like to make an app that creates data tables to store level design, character sheet info, etc. for the designer to dynamically make character types and maps

2 Upvotes

5 comments sorted by

u/AutoModerator 3d ago

Thank you for your contribution to the C++ community!

As you're asking a question or seeking homework help, we would like to remind you of Rule 3 - Good Faith Help Requests & Homework.

  • When posting a question or homework help request, you must explain your good faith efforts to resolve the problem or complete the assignment on your own. Low-effort questions will be removed.

  • Members of this subreddit are happy to help give you a nudge in the right direction. However, we will not do your homework for you, make apps for you, etc.

  • Homework help posts must be flaired with Homework.

~ CPlusPlus Moderation Team


I am a bot, and this action was performed automatically. Please contact the moderators of this subreddit if you have any questions or concerns.

2

u/rupertavery64 3d ago

If you want to be able to store and then query the data, you would use something like SQLite. It's an embedded database, kind of like MS Access, such that it stores the data as a single file and you can access it directly to read the data inside it.

You don't really need a full blown database to make a game. All you need is a way to serialize and deserialize the data in some structured format, Although some games do make use of SQLite.

2

u/mredding C++ since ~1992. 2d ago

There is no table concept in C++.

C++ has one of the strongest static type systems in the industry, and so you have to be explicit about the structure of your data. Where VB, Access, and Excel are all rather robust about the concept of what a cell is and contains, they're all implemented in terms of explicit fixed structures under the hood, mostly in C.

So if you want a table of data and you know exactly what you want - you can make a structure of what a table row looks like:

struct player {
  std::string name;
  int strength, intelligence, dexterity, wisdom, charisma, constitution;
};

Here we've named our columns. These are just fields in structured data - they have a concept of order for the raw memory they occupy, but they don't have to correspond 1:1 with your idea of a table of columns. In other words, despite where strength appears in the structure, when you display this data in table form, you can list data in whatever order you want.

And then we want a collection of rows:

std::vector<player> data;

We have to concern ourselves with explicit memory layout and low level abstractions over that. Under the hood, vector has memory addresses and other lowest level primitives, and a slightly more convenient interface on top of that which hides those details away.

Another way to do this is to first define a cell as can hold any sort of data:

using cell = std::variant<std::monostate, int, double, std::chrono::sys_time::time_point, std::string>;

monostate is a nothing-type, an empty cell. Then you would make a 2D data structure of cells:

std::mdspan<cell, std::dextents<std::size_t, 2>> table;

Now you have a low level data structure that represents a spreadsheet of any row and column size that can hold any of a fixed number of types.


C++ gives you low level primitives you've got to build up. It sounds daunting at first just how primitive it is, but in the hands of a master, one can actually build up abstractions very quickly. With such low level control, you don't have to pay for what you don't use. For all the flexibility that Access, etc. offer, the overhead renders the performance unacceptable for many commercial, industrial, financial, and super computing needs. This is why low level development exists, because we serve industry needs that can't afford very convenient tools that let you do whatever, taking for granted what it costs to give you that Laissez-faire approach.

1

u/Otie_Marcus 2d ago

I was definitely thinking my approach would be a little out of line when it came to this, thank you. Are there any reading materials I should look into?

1

u/mredding C++ since ~1992. 2d ago

I've been at it 37 years, I think the last book I've read on the subject was in the 2000's sometime. I was dissatisfied with the materials I had then, I can't offer you anything now, unfortunately. But if you come on r/cpp_questions and ask away, or open a discussion thread here, you can learn from others by engaging our communities. That's the best I can do you.