#include <iostream>
#include<bits/stdc++.h>
using namespace std;
int main()
{
string str = "";
cout << "Palindrome or not?" << endl;
cout << "Enter text: ";
cin >> str;
isPalindrome(str);
}
void isPalindrome(string str);
{
originalStr = str;
reverse(str.begin(),str.end());
if (originalStr == str)
{
cout<<"Yes!";
}
else
{
cout << "No.";
}
}
-12
A
回答
1
在發佈的代碼中有兩個問題。
isPalindrome
它在main
使用之前未聲明。在main
之前添加聲明。當你定義函數時,你有一個錯字。行尾的
;
是該函數的聲明。然後,你有一個塊代碼。這可以通過簡單地刪除;
來解決。
// Declare the function before main.
void isPalindrome(string str);
int main()
{
string str = "";
cout << "Palindrome or not?" << endl;
cout << "Enter text: ";
cin >> str;
isPalindrome(str);
}
// | the problematic typo.
// v
void isPalindrome(string str) // ;
{
originalStr = str;
reverse(str.begin(),str.end());
if (originalStr == str)
{
cout<<"Yes!";
}
else
{
cout << "No.";
}
}
+0
但是移動;哪一行? – bro
+0
@bro,它需要像我一樣被刪除或註釋掉。 –
0
使用功能
isPalindrome(str);
之前,你必須聲明它,編譯器會知道它的類型。
有函數定義
錯誤分號同樣的函數應返回一個布爾值,給定的字符串是否是迴文與否。該參數應該是對原始字符串的引用。
程序可以看看下面的方式
#include <iostream>
#include <string>
bool isPalindrome(const std::string &s);
int main()
{
std::string s;
std::cout << "Palindrome or not?" << std::endl;
std::cout << "Enter text: ";
std::cin >> s;
std::cout << (isPalindrome(s) ? "Yes!" : "No.") << std::endl;
}
bool isPalindrome(const std::string &s)
{
return s == std::string(s.rbegin(), s.rend());
}
它的輸出可能是
Palindrome or not?
Enter text: abcba
Yes!
相關問題
- 1. 我有一些我不明白的android錯誤,我該如何解決它們?
- 2. 這個錯誤表明什麼?和如何解決它?
- 3. java錯誤不是聲明和';'預計
- 4. Java - 錯誤:<identifier>預計,如何解決它?
- 5. 如何解決樣式表文件的錯誤它顯示它沒有被加載,因爲它的MIME類型。?
- 6. 如何解決這個錯誤?我不能運行它,所以我不知道?
- 7. 選擇沒有聲明,但不知道如何聲明它
- 8. 如何解決Swift中的「預期聲明」錯誤?
- 9. 錯誤:預計聲明
- 10. 錯誤預計聲明C++
- 11. 不能解決預期的聲明錯誤
- 12. sp_executesql預計聲明...嗯,我把它給
- 13. 這個錯誤指的是什麼,以及如何解決它?
- 14. 錯誤。沒有輸入文件指定我如何解決它?
- 15. 顯示所有沒有它們的值的多維數組鍵?
- 16. 奇怪的錯誤消息,如何解決它們?
- 17. window.onload如果錯誤 - 聲明預計
- 18. 這個錯誤意味着什麼以及如何解決它?
- 19. 這個錯誤是什麼意思,以及如何解決它?
- 20. MYSQL錯誤#1064 - 如何解決它?
- 21. Eclipse JRE錯誤?如何解決它?
- 22. 錯誤日誌SIGABRT如何解決它?
- 23. 統一3d錯誤如何解決它
- 24. BGI錯誤,如何解決它?
- 25. 錯誤的NSString聲明,但我沒有看到它
- 26. 它沒有顯示所有圖像
- 27. C++錯誤:預期不合格-ID
- 28. AddressAccessDeniedException:解決它沒有netsh?
- 29. 我得到一個錯誤,我不知道如何解決它
- 30. jquery - 調整它們被聲明的所有字體大小?
能否請您發佈的代碼,而不是它的照片? –
在此處發佈代碼,而不是通過鏈接,特別是不通過位圖。 –
編號[編輯]問題並粘貼在那裏的代碼。 –