C++ conditional include file runtime

后端 未结 4 2018
闹比i
闹比i 2020-12-10 08:15

I am working on a game that is coded in C++ and I would like to make it possible to change language at runtime. Currently, the language is chosen at compile time by includin

4条回答
  •  南方客
    南方客 (楼主)
    2020-12-10 08:22

    You cannot do it with #include, that's compile time only. More specifically, that's pre-processor only, which happens before compilation.

    To get run-time variation, you'll have to move your translations to a text file (something like xml perhaps, but plain text works too) and set up a system that loads the file at startup to populate the strings in the code that need translation.

    This also means all your strings will be dynamically sized at start-up, so the initialization period for the code will increase. But that's the cost of flexibility sometimes.

提交回复
热议问题