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.
Related
This question already has answers here:
How to get current source path in C++ - Linux
(2 answers)
Closed 2 years ago.
I want get current file path,like in a.cpp,I can get
/home/workspace/src/a.cpp
How can I get this path?
You can use the standard macro __FILE__ to which expands to a string literal that contains the path of the current source file.
Starting from C++20, you can use default constructed std::source_location.
I couldn't comment due to the reputation requirement.
But you might find this useful, a way to retrieve directory on Linux & Windows.
How do I get the directory that a program is running from?
Hope this help!
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.
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.
This question already has answers here:
Using C++ to edit the registry
(5 answers)
Closed 9 years ago.
I'm relatively new to coding (even though I've taken a few classes on it) and picked up a job working IT at the library on campus. I do Windows Updates on the computers and come across an error that requires me to alter the registry value of the Windows Update Service. I would like to write a code to do that for me automatically, because it is rather time consuming to alter the registry on five hundred computers. Where do I start? Is it even possible?
To make the changes, I open:
HKEY_LOCAL_MACHINE
Software
Policies
Microsoft
Windows
WindowsUpdate
AU
UseWUServer (this is where I change the value to 0)
In Vista or greater than systems you will need elevated privileges to run anything that will modify the registry. Both answers above would work, I personally have found using power-shell scripts very powerful for this type of problem.
This question already has an answer here:
Sync File System command for windows [closed]
(1 answer)
Closed 8 years ago.
I need to port one app on Windows. Originally that app was written on Linux and it uses Linux specific commands. I stacked at one place with sync(). Windows doesn't have such utility. The code looks like
QSettings *data
...
data->setValue("some_var", var);
data->sync();
sync();
That is a peace of C++ file. I don't know C++. It was written not by me. I use other languages. So how can I make it work on Windows or how can I rewrite that part?
Basically you can ignore the system-specific sync() call. It's not needed, even on linux. QSettings does the right thing for you.
If you have access to all the files you have open, I believe the equivalent of calling sync() on Linux is the same as going over all the file handles and flushing them on Windows, probably by using FlushFileBuffers().
EDIT 1
If you're using the C file interface (since you came from Linux), fflush() is your friend (you still need to have access to all open files.)
EDIT 2
I see there is a _flushall() call you can use. Not sure about its similarity to Linux's sync() but they generylly seem to do the same thing. I'm also a little wary about using functions that start with underscore.