C++ (file handling) [closed] - c++

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 1 year ago.
Improve this question
When we are creating a file using code, it is important to define the extention of file like .txt, .dat , .jpg etc. But in c++ if we ommit the
extention of the file it still work fine. Why is it so? Also explain how the system will decide the correct extention of file as every thing
is in form of 0 and 1 in the memory?

The file extension is more like a suggestion. A ".jpg" file can have text in it and a ".txt" file can be sound. A file can have no extension. Even though it is relatively rare on windows, it is more common on systems like Linux.
We add extensions to tell the operating system and any software that will use the file what it contains. For example, when there is a ".mp3" file, the OS and other programs will know that it is a MPEG sound file.
You don't need extensions if you know what the file contains. However, since other people/programs might not know what the file contains, it is a good idea to use extensions.

Related

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.

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)

what is the difference between .h and .H head file in 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 6 years ago.
Improve this question
what is the difference between .h and .H head file in C++? when I use OpenFOAM which is a Computational Fluid Dynamics open source software developed by C++, I find it's head file name are .H rather than tranditional form .h, Why?
For C++, there is no difference at all.
Apparently, the authors of OpenFOAM just liked .H more than .h
Still, there is something to pay attention to: If you're programming for Unix-like systems (Linux...), file names are case sensitive, so with the wrong name, the file won't be found (=> compiler error).
At the end of the day it doesn't matter for compilers of Windows environment. If you are in an environment where the file name are case sensitive like Ubuntu or other Linux based system then it really matters because of case sensitivity of the file system.
But most often you use the compiler supplied header files and some times you can make your own header files, in the latter case whatever name you give to your header file you have to reference the same in your program and if you are working in Linux environment then you have to be aware of the case sensitivity otherwise in Windows you just give the name of your header file with proper extension where you are referencing it.

C++ multiple big files in one binary file [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 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.

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.