String 如何使用strev反转字符串?

String 如何使用strev反转字符串?,string,String,我想反转字符串数组结果,但当我在联机编译器中运行此代码时,它会显示“strev未声明”。我不明白 for(j=1;j<=test;j++) { cin >> input; strcpy(result,input); length = strlen(result); strrev(result); cout<<"Case "<<j<<": "; for(i = 0;i<=length;i++) { if(result[

我想反转字符串数组结果,但当我在联机编译器中运行此代码时,它会显示“strev未声明”。我不明白

for(j=1;j<=test;j++)
{
cin >> input;
strcpy(result,input);
length = strlen(result);         
strrev(result);
cout<<"Case "<<j<<": ";
for(i = 0;i<=length;i++) 
{
if(result[i]==input[i])
p=0;
else
{
p=1;
break;
}
}
if(p==0)
cout<<"Yes"<<endl;
else
cout<<"No"<<endl;
}
用于(j=1;j>输入;
strcpy(结果,输入);
长度=strlen(结果);
strev(结果);

coutstrev
来自哪里?它不是标准库的一部分。您必须包括定义它的头文件,并包括它

您使用的是C++(
cout
),因此不要使用字符数组和strlen,而是使用std::string。(您需要在文件顶部包含

for(int j=0;j
    for(int j=0;j<test;j++)  // Life is easier if you get in the habit of writing loops like this
    {
        std::string input;  // Don't declare variables until you need them.
        std::cin >> input;
        // Initialize 'result' as the reverse of input directly.
        const std::string result(input.crbegin(), input.crend());
        const char* const answer = (input == result) ? "Yes" : "No";
        std::cout << "Case " << (j+1) << ": " answer << std::endl;  // Offset test case for output.
    }