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.
这篇关于函数调用时未找到标识符错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:函数调用时未找到标识符错误


基础教程推荐
- 如何使图像调整大小以在 Qt 中缩放? 2021-01-01
- 如何“在 Finder 中显示"或“在资源管理器中显 2021-01-01
- 在 C++ 中循环遍历所有 Lua 全局变量 2021-01-01
- 如何在不破坏 vtbl 的情况下做相当于 memset(this, ...) 的操作? 2022-01-01
- 使用从字符串中提取的参数调用函数 2022-01-01
- 管理共享内存应该分配多少内存?(助推) 2022-12-07
- 为 C/C++ 中的项目的 makefile 生成依赖项 2022-01-01
- Windows Media Foundation 录制音频 2021-01-01
- 为什么语句不能出现在命名空间范围内? 2021-01-01
- 从 std::cin 读取密码 2021-01-01