How to read in multiple text files into a program? [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 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)

Related

C++ (file handling) [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 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.

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 implement a parser in C for xml based structured language? [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
I need to implement a simple parser in C (or C++ if C is discouraged for this application) that will read a xml file which will only contain a few elements (that's why called it xml based) i.e., only 4 root elements and and less than 5 child elements totally.
Is it easy to implement or should I use a library like expat? And if it is possible can someone tell me how I can about the process?
Use libxml or libexpat.
There are millions, trillions of examples you can find on net, or even at StackOverflow.
Have a look at this: How can libxml2 be used to parse data from XML?
or use google protobuf,
although it is not xml-based, but it fast.

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.