C++ multiple big files in one binary file [closed] - c++

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 7 years ago.
Improve this question
What is an efficient way to store multiple big files (100Mo to 5Go) in one binary file in c++ ?
For example, if I have an audio file, a very large image file, and a text file, I want to create a binary file that contains these three files and be able to retrieve them latter (to recreate the three original files).
Thanks for your help.

Short answer: Yes.
The long answer is it depends on how you want to package these things, what framing you want to use.
Do you need compression? Do you need random access? One way that's easy to implement is just using the zip container, it's well defined and there's a lot of libraries for creating and manipulating them. The same goes for the tar or cpio format.
The alternative is to write your own container format. This is a lot more difficult, you'll have to write an archiver and extractor.

Related

Easy data storage formats for c++ begginners [closed]

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

how to split and join files in c or rust? [closed]

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
how to split and join files in c or rust?.
I found the split, but saw nothing about joining the files.
I want to split files of various types, from text files to images
want in c or rust because i am using rust, so i can create rust module in c.
[Edit]
I'm making a program that divides files to send by tpc, so I need to divide and merge the files again
In C++, you split files by reading the master and writing to one or more new files.
This technique works with the C language also.
Joining files depends if you want to merge or append. In the append case, the destination file is opened with the "append" and write attribute. The file pointer is set to the end of the file, then stuff is written (appended) to the file.
IMHO, most file operations should be left to the OS as much as possible.

Efficient way to write same data to two files [closed]

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 5 years ago.
Improve this question
Just wondering, what would be the most efficient way to write same data to two files, on linux and C/C++.
For example, this is the most trivial way.
while(1) {
... getting data from somewhere ....
write(fd1, data, datalen);
write(fd2, data, datalen);
}
However, the disadvantage is that kernel needs to copy data twice even though the data is same.
Any thoughts?
what would be the most efficient way to write same data to two files
Write the data to one file only.
Copy that file to another. Use an OS call to do that efficiently (Copy a file in a sane, safe and efficient way).
Another way for step 2 would be to create a hard link (check link()).
However, please watch out of not becomning a victim of premature optimization. I this is not the bottleneck in your program, then just use the trivial, easy-it-read approach.

How to read in multiple text files into a program? [closed]

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 6 years ago.
Improve this question
I am writing a function that will take in a text file and do some manipulation on it. The files are stored in somewhat different places, such as:
/Documents/news/sports/something.txt where sports will be a folder with 20+ txt files
There are 20 more categories, stored such as: /Documents/news/next_category/something_else.txt
So the problem is that I want to pass in every txt file inside each folder inside the news folder, into my program, one by one. Is there a way to do this?
Thanks
i think you want to recursively enumerate the contents of a directory. I would use boost filesystem. It even has a recursive dir walk sample http://www.boost.org/doc/libs/1_61_0/libs/filesystem/doc/index.htm
also look here for other solutions How do you iterate through every file/directory recursively in standard C++?
Not with pure C++. C++ has no concept of directories, so you'll either have to interface with your OS's directory functions (like the C POSIX opendir and family) or use some library (like boost::filesystem)

structure reading C++ [closed]

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.