【发布时间】:2014-05-21 21:29:17
【问题描述】:
我不知道这里出了什么问题。不过我是一个全新的人。
#include <iostream>
#include <stdio.h>
#include <string.h>
#include <locale.h>
#include <tchar.h>
#include <string>
using namespace std;
int main()
{
int string_length;
string word, wordb;
cout << "Type in a word\n";
cin >> word;
string_length = word.length();
for (int i=1; i < (string_length+1); i++)
wordb = wordb + word.at(i);
if (word == wordb)
cout << "The word is the same in any direction.\n";
else
cout << "The word is not the same in any direction.\n";
return 0;
}
很抱歉,如果很明显。
【问题讨论】:
-
i应该从 0 开始,而不是 1。c++ 中的数组是从零开始的。 -
你不知道怎么了?那我们怎么会有线索呢?!你至少有错误信息吗?
-
这应该引发异常。阅读它的内容并进行调试。
-
您是否尝试通过它进行调试?您可以在调试器中对变量设置监视表达式。
-
你正在按照与
word相同的顺序构建wordb。修复索引(从 0 开始,而不是从 1 开始)后,考虑从word的 end 开始访问字符,然后向后工作。
标签: c++