在函数调用时找不到标识符错误

编程入门 行业动态 更新时间:2024-10-23 19:33:17
本文介绍了在函数调用时找不到标识符错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我有一个程序在这里我反转输入字符串的大小写。这是我的.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.

更多推荐

在函数调用时找不到标识符错误

本文发布于:2023-10-07 15:27:46,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1469774.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:标识符   找不到   函数   错误

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!