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!
Related
This question already has an answer here:
Visual C++ dump preprocessor defines
(1 answer)
Closed 2 years ago.
Sorry for the what I am sure is a basic question, but I must not be using the right terms when searching for an answer with code that has hundreds of header files. Simply searching the files for #define statements is tedious. Is there an easy way in Visual Studio or VSCode to just have it step through the files and give me a list of all values literals and their values?
The closest you can get is to use the /P compiler switch to dump the preprocessed output to a file. It's going to be pretty huge, but it shows you precisely what the compiler is working with, and you can do a text search in the output file to find what you're looking for.
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:
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.
This question already has answers here:
Closed 11 years ago.
Possible Duplicate:
How to copy text file in C or C++?
I need a code which specifically look up a directory and find a pre-specified file name then copy it to another folder. It sounds easy but couldnt do it. Can anbody help me?
thanks
Some functions you may find useful from WINAPI:
FindFirstFile()
FindNextFile()
CopyFile()
boost has a filesystem library which has a copy_file function.
Last time I checked, C++ doesn't offer a file copy function. You need to open the file, read in its data into a local buffer, then make a new file, and write the contents of the local buffer into the new file.
File IO Reference
This question already has answers here:
Closed 12 years ago.
Possible Duplicate:
In C++, How to get MD5 hash of a file?
I am currently using Ubuntu and am wishing to calculate the MD5 of a char*. was wondering if there is a pre-installed library that would just need including, or would I have to download a specially designed one?
Include openssl/MD5.h and use the following to calculate the hash
MD5(<characters>, <length of it>, <the result(pointer)>);
Have a look at hashlib++ or Crypto API.
I would rephrase the question. In the context of C++, you're asking for the MD5 sum of a single pointer to char, which is practically meaningless.
That 'char *' could refer to a location in memory that refers to the file content you are after, in which case you're going to need a size somewhere, or it could refer to a null-terminated string, or a pascal-string, or, really, anything else.
With ubuntu, I'd do something like 'apt-cache search md5' and see what you get. On my debian system, libgcrypt11 looks intriguing.