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 出错.由于某种我不确定的原因,Main 没有看到 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
}
}
感谢任何其他有关语法或语义的提示.
Any other tips for syntax or semantics is appreciated.
推荐答案
在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.
这篇关于函数调用时未找到标识符错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:函数调用时未找到标识符错误


基础教程推荐
- 如何在 C++ 中初始化静态常量成员? 2022-01-01
- 常量变量在标题中不起作用 2021-01-01
- 静态库、静态链接动态库和动态链接动态库的 .lib 文件里面是什么? 2021-01-01
- 如何将 std::pair 的排序 std::list 转换为 std::map 2022-01-01
- 在 C++ 中计算滚动/移动平均值 2021-01-01
- 如何检查GTK+3.0中的小部件类型? 2022-11-30
- 这个宏可以转换成函数吗? 2022-01-01
- C++结构和函数声明。为什么它不能编译? 2022-11-07
- 我有静态或动态 boost 库吗? 2021-01-01
- 如何通过C程序打开命令提示符Cmd 2022-12-09