1. <small id='JCeI6'></small><noframes id='JCeI6'>

    2. <i id='JCeI6'><tr id='JCeI6'><dt id='JCeI6'><q id='JCeI6'><span id='JCeI6'><b id='JCeI6'><form id='JCeI6'><ins id='JCeI6'></ins><ul id='JCeI6'></ul><sub id='JCeI6'></sub></form><legend id='JCeI6'></legend><bdo id='JCeI6'><pre id='JCeI6'><center id='JCeI6'></center></pre></bdo></b><th id='JCeI6'></th></span></q></dt></tr></i><div id='JCeI6'><tfoot id='JCeI6'></tfoot><dl id='JCeI6'><fieldset id='JCeI6'></fieldset></dl></div>
    3. <tfoot id='JCeI6'></tfoot>
        <bdo id='JCeI6'></bdo><ul id='JCeI6'></ul>
    4. <legend id='JCeI6'><style id='JCeI6'><dir id='JCeI6'><q id='JCeI6'></q></dir></style></legend>
    5. 在 C++ 中使用表示变量名称的字符串访问变量值

      时间:2023-05-24
    6. <tfoot id='vAqjg'></tfoot>

          <bdo id='vAqjg'></bdo><ul id='vAqjg'></ul>

            <i id='vAqjg'><tr id='vAqjg'><dt id='vAqjg'><q id='vAqjg'><span id='vAqjg'><b id='vAqjg'><form id='vAqjg'><ins id='vAqjg'></ins><ul id='vAqjg'></ul><sub id='vAqjg'></sub></form><legend id='vAqjg'></legend><bdo id='vAqjg'><pre id='vAqjg'><center id='vAqjg'></center></pre></bdo></b><th id='vAqjg'></th></span></q></dt></tr></i><div id='vAqjg'><tfoot id='vAqjg'></tfoot><dl id='vAqjg'><fieldset id='vAqjg'></fieldset></dl></div>

                  <tbody id='vAqjg'></tbody>
              • <legend id='vAqjg'><style id='vAqjg'><dir id='vAqjg'><q id='vAqjg'></q></dir></style></legend>

              • <small id='vAqjg'></small><noframes id='vAqjg'>

                本文介绍了在 C++ 中使用表示变量名称的字符串访问变量值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

                问题描述

                限时送ChatGPT账号..

                如果标题不清楚,我会尽量澄清我的问题:

                If the title was not clear, I will try to clarify what I am asking:

                假设我有一个名为 counter 的变量,我知道我可以通过执行以下操作来查看其当前值:

                Imagine I have a variable called counter, I know I can see its current value by doing something like:

                std::cout << counter << std::endl;
                

                但是,假设我有很多变量,并且直到运行时我不知道要查看哪些变量.

                However, assume I have lots of variables and I don't know which I'm going to want to look at until runtime.

                有谁知道我可以通过使用变量名称获取变量值的方法,例如:

                Does anyone know a way I can fetch the value of a variable by using its name, for example:

                std::cout << valueOf("counter") << std::endl;
                

                我觉得能够做到这一点可能会使调试大型复杂项目变得更容易.

                I feel being able to do this might make debugging large complex projects easier.

                提前感谢您的时间.

                更新:所提供的所有答案都是有效且有用的,但重点是 C++ 中不存在反射(阅读推荐的链接后很清楚原因).

                Update: All the answers provided are valid and useful, however the main point is that reflection does not exist in C++ (and after reading the link recommended it is clear why).

                推荐答案

                如前所述,您正在寻找 C++ 中的反射.它没有那个,这个答案解释了原因.

                As has been mentioned, you are looking for reflection in C++. It doesn't have that, and this answer explains why.

                这篇关于在 C++ 中使用表示变量名称的字符串访问变量值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持html5模板网!

                上一篇:什么时候分配/初始化函数级静态变量? 下一篇:未初始化的变量会发生什么?C++

                相关文章

                最新文章

                <small id='WLjDs'></small><noframes id='WLjDs'>

                <tfoot id='WLjDs'></tfoot>

              • <i id='WLjDs'><tr id='WLjDs'><dt id='WLjDs'><q id='WLjDs'><span id='WLjDs'><b id='WLjDs'><form id='WLjDs'><ins id='WLjDs'></ins><ul id='WLjDs'></ul><sub id='WLjDs'></sub></form><legend id='WLjDs'></legend><bdo id='WLjDs'><pre id='WLjDs'><center id='WLjDs'></center></pre></bdo></b><th id='WLjDs'></th></span></q></dt></tr></i><div id='WLjDs'><tfoot id='WLjDs'></tfoot><dl id='WLjDs'><fieldset id='WLjDs'></fieldset></dl></div>
                  <bdo id='WLjDs'></bdo><ul id='WLjDs'></ul>
                    <legend id='WLjDs'><style id='WLjDs'><dir id='WLjDs'><q id='WLjDs'></q></dir></style></legend>