首页 > 其他 > 详细

identifier not found error on function call

时间:2014-02-14 10:34:52      阅读:391      评论:0      收藏:0      [点我收藏+]

在C++工程中,自定义一个方法 void fgetsDemo(),在main 方法中调用,源代码如下:

bubuko.com,布布扣
#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 error\n" );
      else
         printf( "%s", line);
      fclose( stream );
   }
}
View Code

 

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

bubuko.com,布布扣

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

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

 

解决方案1:在 main 方法前声明这个自定义的方法,

bubuko.com,布布扣
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

identifier not found error on function call

原文:http://www.cnblogs.com/cindy-hu-23/p/3548459.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!