Reading from set of files [duplicate] - c++

This question already has answers here:
How can I get the list of files in a directory using C or C++?
(33 answers)
Closed 9 years ago.
I am a newbie so please don't be harsh on me for asking simple questions. my main question is how can I read from several files located in a directory sequently using a loop in c++ and perform some actions on them?
My code is like this:
string corpus = "corpus.txt";
myfile.open(corpus);
if (myfile.is_open())
while (!myfile.eof())
{
//Do something
}//end of while
MergeFiles(corpus,count);`
How can I do this actions on a set of files instead of just one.

Looks like you could do one of the following:
use windows APIs
use third party code
It looks like the simplest way is using diren.h. Look for at the sample code here:
How can I get the list of files in a directory using C or C++?
you can use the boost libraries, more specific - the filesystem library. This is more powerful but complicated solution, requires you to use iterators and higher programming methods.
using the windows API is not recommended because it requires dipper understanding of windows, and won't result a portable code. If you want to use it, there is an example in MSDN.

Related

Is it possible to decompile a C++ executable file [duplicate]

This question already has answers here:
Is it possible to "decompile" a Windows .exe? Or at least view the Assembly?
(16 answers)
Is there a C++ decompiler? [closed]
(5 answers)
Closed 4 years ago.
I lost the source code to an executable file but still have the actual file. Is there any way to retrieve the original C++ code?
Duplicate of this question here.
Yes, it is possible, however when it comes to peeking function bodies and the like, you might have a little less luck. Operating systems like Kali Linux specialize in de-compilation and reverse engineering, so maybe look into a VM of that. And of course, windows has a lot of applications you can use as well to check the application code.
Look over the other question for specific app suggestions. :)
Edit : You will most likely have lost all your logic and function bodies, but you might be able to recover the overall structure. It's your EXE so you might be more familiar with how it was all connected up.
You cannot get the original source code but you can decompile the binary into source code using tools given in this similar question: Is there a C++ decompiler?
The output source code will not look like the original as the compiler will have optimised the original source when generating the executable.
Short answer NO.
Long answer, because C++ doesn't use some intermediate code like C# or Java you cannot decompile the app in some readable format. But if you can read assembly maybe you can save some time.

C++ - Create function at runtime [duplicate]

This question already has answers here:
Is it possible to create a function dynamically, during runtime in C++?
(14 answers)
Closed 8 years ago.
In C++, I have to make some user-defined actions on each cells of a big table.
Because of the size of the table, I'd like not to use interpreted instructions but to compile during runtime a function that I will call on each cell.
The user-defined actions are pretty simple :
if ((state1 && state2) || state3) then change_a_value_in_memory
That's why I don't need to use the LLVM or other JIT libraries.
I hesitate to just use mmap and add the code in hex directly.
I'd like to know if it exists better solutions, or, if not, where I can find the basic format of a C++ function code to directly write it in memory.
Thanks, and sorry for my english :/
This is not the most elegant, but it works always: generate a file with the C++ code of your function, call the compiler using system(), load the generated .so file using dlopen, and use the function!
This will take some time (due to the compiler call), but if you keep the function and maintain a database of the functions you already have, then you can save the amount of compilations.

file modification callbacks using c++? [duplicate]

This question already has answers here:
Is there a command like "watch" or "inotifywait" on the Mac?
(16 answers)
Closed 9 years ago.
i require a callback within my code (in C++) which fires every time a particular file is modified (after a save), i am using a Mac however not Xcode, i am building my code using g++, documentation for this seems to be very limited. Does anyone have any example code which performs this functionality? Or can point me in the right direction as to where to look?
On Linux you would use ionotify, but OSX has FSEvents. It seems it will only notify you about changes to directories, it's up to you to then see if the event was about your file or not. There's a C API. This question has some examples.

Searching Directories "backwards" using windows API in C++ [duplicate]

This question already has answers here:
Closed 10 years ago.
Possible Duplicate:
How to get the parent directory of the current folder in a C program?
I am using the C++ Windows API and I look for folders and directories given a specific directory path initially (i.e. C:\...\ProjectXX). I use in particular the functions FindFirstFile() and FindNextFile(). I want however sometimes to move "backwards" in a directory, namely to get the "parent" of the given directory (the folder which contains the directory given). In what way is this possible and under the use of what functions?
C++, unlike C, has a method for it: .remove_leaf(). But you're not using C++ functions, you're using WinAPI functions, so PathRemoveFileSpec() would be more fitting.

How do I disable the risky functions in lua the easiest way possible? [duplicate]

This question already has answers here:
Closed 11 years ago.
Possible Duplicates:
How can I limit lua possibilities (calling OS functions, modules, etc.)
How can I create a secure Lua sandbox?
luaL_openlibs(m_pState);
I use this function to load all the libs.I would like to skip all the dangerous libs like IO but I just cant find any documentation on how to disable a lib.
How do I disable certain libs? Are there more dangerous libs that can gain the script access to the system?
Add a copy of linit.c to your project and remove any libraries that you deem dangerous. To remove individual functions, set them to nil. See also the source of the Lua demo.