我有一个程序,使用for循环打印出字符串的字符.它还必须反向打印相同的字符,这是我遇到问题的地方.有人可以帮我弄清楚为什么第二个for循环没有执行?
int main()
{
string myAnimal;
cout << "Please enter the name of your favorite animal.\n";
cin >> myAnimal;
// This loop works fine
int i;
for(i = 0; i < myAnimal.length(); i++){
cout << myAnimal.at(i) << endl;
}
// This one isn't executing
for(i = myAnimal.length(); i > -1; i--){
cout << myAnimal.at(i) << endl;
}
return 0;
}
Run Code Online (Sandbox Code Playgroud) 我正在做一个要求我使用函数检查两个字符串是否相等的赋值.我一直在第20行得到一个解析错误,这里调用了函数,我不知道出了什么问题.如果您发现可能导致问题的原因,请查看并告诉我.谢谢!
#include <iostream>
#include <string>
using namespace std;
bool checker(string firstWordParameter, string secondWordParameter);
int main()
{
string firstWord, secondWord;
bool match;
cout << "Hello user.\n"
<< "This program will determine whether two words are the same.\n"
<< "Please enter your first word you would like to check: ";
getline(cin, firstWord);
cout << "Great, now enter the second word: ";
getline(cin, secondWord);
match = bool checker(firstWord, secondWord);
if(match == true){
cout << "Match.";
}else{
cout << "Totally not a match.";
} …Run Code Online (Sandbox Code Playgroud)