在函数调用时找不到标识符错误 [英] Identifier not found error on function call
本文介绍了在函数调用时找不到标识符错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有一个程序在这里我反转输入字符串的大小写。这是我的.cpp文件中的代码,我使用Visual Studio C ++ IDE。我不知道我需要一个头文件或者如果我需要一个,使这项工作。
I have a program here where I invert the case of an entered string. This is the code in my .cpp file and I am using Visual Studio C++ IDE. I am not sure what I need in a header file or if I need one to make this work.
错误与我的函数调用swapCase。由于某些原因,我不知道主要没有看到swapCase。
Error with my function call swapCase. Main does not see swapCase for some reason that I'm not sure of.
#include <cctype>
#include <iostream>
#include <conio.h>
using namespace std;
int main()
{
char name[30];
cout<<"Enter a name: ";
cin.getline(name, 30);
swapCase(name);
cout<<"Changed case is: "<< name <<endl;
_getch();
return 0;
}
void swapCase (char* name)
{
for(int i=0;name[i];i++)
{
if ( name[i] >= 'A' && name[i] <= 'Z' )
name[i] += 32; //changing upper to lower
else if( name[i] >= 'a' && name[i] <= 'z')
name[i] -= 32; //changing lower to upper
}
}
或语义。
推荐答案
在main函数之前添加此行:
Add this line before main function:
void swapCase (char* name);
int main()
{
...
swapCase(name); // swapCase prototype should be known at this point
...
}
这被称为前向声明:当编译函数调用时,编译器需要知道函数原型。
This is called forward declaration: compiler needs to know function prototype when function call is compiled.
这篇关于在函数调用时找不到标识符错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文