【发布时间】:2014-05-03 03:09:41
【问题描述】:
大家好,我是 C++ 初学者,我正在开发程序来检查用户输入的字符串以确定它是否是回文。我有大部分代码,但仍然有两个问题,第一个是 In function ‘bool PalindromeTest()’,第二个错误是:error: ‘strrev’ is not declared in this scope
#include <iostream>
#include <cstring>
using namespace std;
char s[100];
char sr[100];
void InputString();
bool PalindromeTest();
void PrintMessage();
int main()
{
InputString();
return 0;
}
void InputString(int n=0)
{
cout<<"Input the string you wish to be tested";
cin.getline(s, 100);
if(strlen(s)>n)
PalindromeTest();
}
bool PalindromeTest()
{
bool rvalue = true;
strcpy(sr, s);
strrev(sr);
if(strcmp(s, sr) == 0)
{
rvalue=true;
PrintMessage();
}
else
{
rvalue=false;
PrintMessage();
}
void PrintMessage(bool rvalue)
{
if(true == rvalue)
cout<<"The entered string IS a palindrome"<<endl;
else
cout<<"The entered strins IS NOT a palindrome"<<endl;
}
【问题讨论】:
-
对于
strrev-- 看这里:stackoverflow.com/questions/8534274/… -
]$ g++ uu.cpp uu.cpp: In function ‘bool PalindromeTest()’: uu.cpp:32: error: ‘strrev’ is not declared in this scope
-
...那么是什么让您认为该功能存在?
-
如果你认为它不存在,你为什么要调用它?
-
使用
std::string而不是 char 数组,您自己会轻松很多
标签: c++