Changing const values ​​during development without recompiling everything

Now I have a significant amount of potential magic numbers stored in constants. They are very adaptable between each assembly. egconst int numAPPLES = 25

right now they are defined at the top of each associated class header. But sometimes they need to be exchanged, and I still need to:

  • Copy definition; and conflicting risks.
  • include an extra header (this is what I did)

I previously had them all in options.h, which is great because I can see them all together, but changing the number will obviously lead to a complete overhaul.

If this is important, I am using VS 2010.

What is the best way to allow these numbers to change? I am wondering how I can add a TXT file to a VS project and then extract variables from it.

data types (for now) only charandint

I also do not want to have all the library dependency just to access them. But a simple recommended class; or a way to build your own, it would be great.

thank!


edit: does this look good to you guys ?: http://www.codeproject.com/KB/cpp/IniReader.aspx

+3
source share
3 answers

If you need constants at compile time, you really need to recompile when they change.

If you only need values ​​at runtime, you can declare them as

extern const int numAPPLES;

and put the actual values ​​in a separate .cpp file. When you change the value, you just need to recompile this file.

+8
source

.ini, , ? GetPrivateProfileInt/GetPrivateProfileString. , Windows.

Try.ini:

..
[Section1]
Const1 = 1
..

:

CString FileName = _T("Try.ini");
int Value = GetPrivateProfileInt( "Section1", "Const1", DEFAULT_ERROR, FileName );
if( Value == DEFAULT_ERROR)
  return ERROR;

+2

: , . , ? ++, char * ?

, , , . , , .

, , , Boost.Program_options.

+1

Source: https://habr.com/ru/post/1795582/


All Articles