这让我很困惑,简单的代码:
int main()
{
typedef std::string::size_type stype;
std::cout << "What is your first name?\n";
std::string first,second,fullname;
std::cin >> first;
std::cout << "What is your second name?\n";
std::cin >> second;
char * backwards;
fullname = first + " " + second;
stype fnsize = fullname.size();
backwards = new char [fnsize];
stype b = 0;
for(stype a = fnsize; a != 0; --a)
{
backwards[b++] = fullname[a - 1];
}
std::cout << backwards << std::endl;
return 0;
}
大部分时间都有效,但是当我写一个像我自己的名字stanislaw terziev时,我得到一个输出veizret walsinatsslaw而不是veizret walsinats
为什么会这样?