identifier not found error on function call

在C++工程中,自定义一个方法 void fgetsDemo(),在main 方法中调用,源代码如下:
identifier not found error on function callidentifier not found error on function call

#include "stdafx.h"
#include <stdio.h>
#include <stdlib.h>
#include <string.h>

int _tmain(int argc, _TCHAR* argv[])
{
    /*Example for fgets*/
    fgetsDemo();

    return 0;
}

void fgetsDemo()
{
FILE *stream;
   char line[100];

   if( fopen_s(&stream, "c:crt_fgets.txt", "r" ) == 0 )
   {
      if( fgets( line, 100, stream ) == NULL)
         printf( "fgets errorn" );
      else
         printf( "%s", line);
      fclose( stream );
   }
}

View Code

编译,出现 error C3861: 'fgetsDemo': identifier not found,即标示符未找到的错误。

identifier not found error on function call

在C++ 中,要调用变量或方法,需要提前声明。

编译器会从上到下的读取你的源代码,如果自定义的方法没有提前声明,那么编译器读到这个方法时,就不知道它是何物,就会出现 “标示符未找到”的错误。

解决方案1:在 main 方法前声明这个自定义的方法,
identifier not found error on function callidentifier not found error on function call

void fgetsDemo();
int _tmain(int argc, _TCHAR* argv[])
{
    /*Example for fgets*/
    fgetsDemo();

    return 0;
}

View Code

解决方案2:将整个方法体 移到 main 方法之前。

参考链接:

http://stackoverflow.com/questions/8329103/identifier-not-found-error-on-function-call
原文链接: https://www.cnblogs.com/cindy-hu-23/p/3548459.html

欢迎关注

微信关注下方公众号,第一时间获取干货硬货;公众号内回复【pdf】免费获取数百本计算机经典书籍

原创文章受到原创版权保护。转载请注明出处:https://www.ccppcoding.com/archives/120021

非原创文章文中已经注明原地址,如有侵权,联系删除

关注公众号【高性能架构探索】,第一时间获取最新文章

转载文章受原作者版权保护。转载请注明原作者出处!

(0)
上一篇 2023年2月10日 下午6:15
下一篇 2023年2月10日 下午6:16

相关推荐