Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 2 years ago.
Improve this question
I’m kind of confused how flat buffers work.
I tried looking at the docs but am still confused.
Basically, what I need to do is
Load JSON data (or actually, ANY data format as long as it’s changeable by another user and readable) from a file into a struct or read the fields one by one.
Save the struct back into any readable data format as a file once the app closes
That’s why I’m confused on flatbuffers.
How do you change the file once it’s saved? Is the saved result binary? Or is that not what it was built for?
I’m using RapidJson currently.
The usage is read text data into a struct, when app ends save struct into text that’s modifiable.
Flatbuffers are a compact binary representation of a given data structure, with the promise that it can be used "straight from the wire", without any deserialization after the fact. By contrast, protocol buffers fill the same niche but need to be (de)serialized.
For your purposes, just stick with JSON or YAML, since "readable by humans" is a priority.
Related
Closed. This question is opinion-based. It is not currently accepting answers.
Want to improve this question? Update the question so it can be answered with facts and citations by editing this post.
Closed 1 year ago.
Improve this question
My question is particularly pointed towards what's neat and efficient and won't get me made fun of as a programmer.
So basically I want to store a huge file of names of PNGS. So of course I'd use an array of strings in order to store all those names. But my question is should I store these strings in something like a binary file? Or should I just put them straight onto the script? I personally hate the idea of using a text file to store them but what do I know.
If I were to put them on a script then it would look something like this:
const std::string tileFile[textureAmount] ={
"Grass.png",
"Dirt.png"
};
But this just looks really stupid to me for some reason. How would one handle a situation like this more professionally?
A character is 1 byte, whether you write a text file or a binary file. The only savings would be if you did some encoding or compression to it, and text does compress nicely since not all the bits in the chars are usually used.
But one pragmatic rule for programming is, "remember the power of plain text". Binary is nice, but if you don't need it, don't use it. Text is easier to work with, to read, to understand when it is corrupted, to use with other tools, and so on. If you can map the data into memory, use binary. If you're going to gzip it or something like that, use binary. If you're just storing the data and it's not excessively big, then I'd recommend a nice, easily parsed text file.
And don't feel ashamed of it. :)
Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 2 years ago.
Improve this question
I have a Word document which is a template, and inside this document I whish to have some variable fields. Through my program I want to change these values on demand (e.g. calling Word and passing some parameters to it using a C++ program). I've searched a lot but so far I couldn't find good examples of that.
Microsoft Word has a proprietary file format which I imagine will be incredibly tricky to parse programmatically (i.e. by opening the file using an fstream).
If you are keen on using Microsoft products, your best bet may be to use Microsoft Access (a database manager), insert the data you want as a row in some database, and then create some formatted form which uses this data and generates a printable document for you. Here's a useful link: Create Form in Microsoft Access
Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 2 years ago.
Improve this question
I'm making a c++ program and need a way to store data for users and things like that. I've tried JSON, but the libraries are very difficult to use, at least for a beginner like me. I am looking for a key-value pair type format. JSON work, if I could find an easier library for that.
If you are looking for storage formats for data, then options are -
XML (3rd party libraries available)
JSON (3rd party libraries available)
INI file (key value pair in text file)
CSV format (text file)
Object serialization
etc
Storage mechanisms are -
File store (XML, JSON, CSV as plain text file)
Database (RDBMS, Object store)
In memory objects
Above are few regularly used storage techniques in C++ (and many other languages also).
~Nilesh
Closed. This question is opinion-based. It is not currently accepting answers.
Want to improve this question? Update the question so it can be answered with facts and citations by editing this post.
Closed 8 years ago.
Improve this question
In the Java and JavaScript world json files are a standard way of storing complex data objects in files. Does C++ have its own standards in this matter too?
While I would disagree that storing JSON files is a "standard way" (esp. for Java), there are many different ways to achieve that in any language. It totally depends on your actual use case. You can write primitive values to files, key/value pairs of some sort, XML, JSON, YAML, write to a Database, send data to web services, ...
No, there is no standard way for generically storing data to files.
Not really. You could use static data (and have its constructor called, conceptually before main in an unspecified order).
You could also have a big literal string in your file -the raw string literal
feature of C++11 is handy- and have some code (e.g. a constructor which would accept a string encoded in JSON form) parse it.
They are just one way of storing data. Not "standard".
XML is another for example. All of these are available in C++ along with others
Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 8 years ago.
Improve this question
I have the following problem:
I have a configuration file that consists a description of fields , which I read it and then parse it. I want to move it into the code to compile it inside.
How would you do that as bug structure ??? or else ?
Thanks
I wouldn't move it into the code, I'd leave the configuration file as a configuration file.
If you really must do this, you can just embed the file as a string resource into the application and use that - that way you'd change only a minimal amount of existing code. The way you do this depends upon your platform.
If thats not feasible (for whatever reason) I'd set up a single configuration class / namespace to contain all the values.
It's not very clear what are you exactly asking.
If you are looking for on-the-fly code execution (like eval() function in some languages), then there is no such thing in C++. It's not an interpreted language which can be read and executed line-by-line, it needs to be compiled every time code changes. While it technically is possible to write self-changing code, it's probably not worth the effort.