<small id='5lQ7u'></small><noframes id='5lQ7u'>

    1. <i id='5lQ7u'><tr id='5lQ7u'><dt id='5lQ7u'><q id='5lQ7u'><span id='5lQ7u'><b id='5lQ7u'><form id='5lQ7u'><ins id='5lQ7u'></ins><ul id='5lQ7u'></ul><sub id='5lQ7u'></sub></form><legend id='5lQ7u'></legend><bdo id='5lQ7u'><pre id='5lQ7u'><center id='5lQ7u'></center></pre></bdo></b><th id='5lQ7u'></th></span></q></dt></tr></i><div id='5lQ7u'><tfoot id='5lQ7u'></tfoot><dl id='5lQ7u'><fieldset id='5lQ7u'></fieldset></dl></div>
    2. <legend id='5lQ7u'><style id='5lQ7u'><dir id='5lQ7u'><q id='5lQ7u'></q></dir></style></legend>

      1. <tfoot id='5lQ7u'></tfoot>
          <bdo id='5lQ7u'></bdo><ul id='5lQ7u'></ul>

        什么是“未声明的标识符"错误,我该如何解决?

        时间:2023-10-18
        • <bdo id='7OJgx'></bdo><ul id='7OJgx'></ul>

            <legend id='7OJgx'><style id='7OJgx'><dir id='7OJgx'><q id='7OJgx'></q></dir></style></legend>

            <small id='7OJgx'></small><noframes id='7OJgx'>

              <tfoot id='7OJgx'></tfoot>
            1. <i id='7OJgx'><tr id='7OJgx'><dt id='7OJgx'><q id='7OJgx'><span id='7OJgx'><b id='7OJgx'><form id='7OJgx'><ins id='7OJgx'></ins><ul id='7OJgx'></ul><sub id='7OJgx'></sub></form><legend id='7OJgx'></legend><bdo id='7OJgx'><pre id='7OJgx'><center id='7OJgx'></center></pre></bdo></b><th id='7OJgx'></th></span></q></dt></tr></i><div id='7OJgx'><tfoot id='7OJgx'></tfoot><dl id='7OJgx'><fieldset id='7OJgx'></fieldset></dl></div>
                    <tbody id='7OJgx'></tbody>
                  本文介绍了什么是“未声明的标识符"错误,我该如何解决?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                  问题描述

                  什么是未声明的标识符错误?什么是常见原因,我该如何解决?

                  错误文本示例:

                  • 对于 Visual Studio 编译器:error C2065: 'cout' : undeclared identifier
                  • 对于 GCC 编译器:'cout' 未声明(首次在此函数中使用)

                  解决方案

                  最常见的原因是忘记包含包含函数声明的头文件,例如,这个程序会给出'undeclared identifier'错误:

                  >

                  缺少标题

                  int main() {std::cout <<你好世界!"<<std::endl;返回0;}

                  要修复它,我们必须包含标题:

                  #include int main() {std::cout <<你好世界!"<<std::endl;返回0;}

                  如果您编写了标题并正确包含了它,则标题可能包含错误的include guard.

                  要了解更多信息,请参阅 http://msdn.microsoft.com/en-us/library/aa229215(v=vs.60).aspx.

                  拼写错误的变量

                  初学者错误的另一个常见原因是变量拼写错误:

                  int main() {int aComplicatedName;AComplicatedName = 1;/* 注意大写 A */返回0;}

                  范围不正确

                  比如这段代码会报错,因为你需要使用std::string:

                  #include int main() {std::string s1 = "你好";//正确的.字符串 s2 = "世界";//错误 - 会出错.}

                  声明前使用

                  void f() { g();}无效 g() { }

                  g 在第一次使用之前没有被声明.要修复它,请在 f 之前移动 g 的定义:

                  void g() { }无效 f() { g();}

                  或者在f之前添加一个g的声明:

                  void g();//宣言无效 f() { g();}void g() { }//定义

                  stdafx.h 不在顶部(VS 特定)

                  这是特定于 Visual Studio 的.在VS中,您需要在任何代码之前添加#include "stdafx.h".编译器忽略之前的代码,所以如果你有这个:

                  #include #include "stdafx.h"

                  #include 将被忽略.你需要把它移到下面:

                  #include "stdafx.h"#include 

                  随意编辑这个答案.

                  What are undeclared identifier errors? What are common causes and how do I fix them?

                  Example error texts:

                  解决方案

                  They most often come from forgetting to include the header file that contains the function declaration, for example, this program will give an 'undeclared identifier' error:

                  Missing header

                  int main() {
                      std::cout << "Hello world!" << std::endl;
                      return 0;
                  }
                  

                  To fix it, we must include the header:

                  #include <iostream>
                  int main() {
                      std::cout << "Hello world!" << std::endl;
                      return 0;
                  }
                  

                  If you wrote the header and included it correctly, the header may contain the wrong include guard.

                  To read more, see http://msdn.microsoft.com/en-us/library/aa229215(v=vs.60).aspx.

                  Misspelled variable

                  Another common source of beginner's error occur when you misspelled a variable:

                  int main() {
                      int aComplicatedName;
                      AComplicatedName = 1;  /* mind the uppercase A */
                      return 0;
                  }
                  

                  Incorrect scope

                  For example, this code would give an error, because you need to use std::string:

                  #include <string>
                  
                  int main() {
                      std::string s1 = "Hello"; // Correct.
                      string s2 = "world"; // WRONG - would give error.
                  }
                  

                  Use before declaration

                  void f() { g(); }
                  void g() { }
                  

                  g has not been declared before its first use. To fix it, either move the definition of g before f:

                  void g() { }
                  void f() { g(); }
                  

                  Or add a declaration of g before f:

                  void g(); // declaration
                  void f() { g(); }
                  void g() { } // definition
                  

                  stdafx.h not on top (VS-specific)

                  This is Visual Studio-specific. In VS, you need to add #include "stdafx.h" before any code. Code before it is ignored by the compiler, so if you have this:

                  #include <iostream>
                  #include "stdafx.h"
                  

                  The #include <iostream> would be ignored. You need to move it below:

                  #include "stdafx.h"
                  #include <iostream>
                  

                  Feel free to edit this answer.

                  这篇关于什么是“未声明的标识符"错误,我该如何解决?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                  上一篇:static_cast<T> 是什么?对 T&amp; 做些什么? 下一篇:为什么 vector&lt;bool&gt;::reference 不返回对 bool 的引用?

                  相关文章

                  • <bdo id='hCZO6'></bdo><ul id='hCZO6'></ul>
                      <legend id='hCZO6'><style id='hCZO6'><dir id='hCZO6'><q id='hCZO6'></q></dir></style></legend>
                      <tfoot id='hCZO6'></tfoot>

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

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