T
T
Ternick2020-08-28 20:52:11
C++ / C#
Ternick, 2020-08-28 20:52:11

Is it possible to process strings at compile time?

I have a program that stores many long paths to its elements in its code. I would like to do something like a macro or something similar. For the following to happen.

wstring data = WMACROS(L"%pathToLogs%\\Errors.log");

and after compilation in the .application you will find the following:
wstring data = L"ProgramData\\AllLogs\\WebData\\{СЛУЧАЙНАЯ СТРОКА, КОТОРАЯ ГЕНЕРИРУЕТСЯ ПРИ КОМПИЛЯЦИИ}\\Logs\\Errors.log";

Of course, you can make a function that will manage it all or add keys with paths to the registry in HKCU \ Enviroment, but you don’t want to clog the user environment and I think there is another solution to this problem, no?

Well, here's how to make a kind of macro that will give a string in which there is a random string that is generated during compilation.

Answer the question

In order to leave comments, you need to log in

2 answer(s)
J
jcmvbkbc, 2020-08-28
@Ternick

A RANDOM STRING THAT IS GENERATED WHEN COMPILING

Doubtful looks like a new random string that is generated with each compilation. But even if so, then a simple and fairly universal solution would be to generate a source with this line, for example, a script or an external program call. This generation can be called on the desired event (for example, every compilation), or manually. And then use this source as any other.

T
Timur Pokrovsky, 2020-08-28
@Makaroshka007

You can do this:

#define TO_LOGS(str) "ProgramData\\AllLogs\\WebData\\14.08.2020\\Logs\\" str

cout << TO_LOGS("Errors.log") << endl; 
//=> ProgramData\AllLogs\WebData\14.08.2020\Logs\Errors.log

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question