【发布时间】:2014-01-10 11:57:19
【问题描述】:
#include<iostream>
#include<string>
using namespace std;
void reverse(char* str)
{
char *new_str = str;
while(*new_str != '\n'){
new_str++;
}
while(new_str != str){
cout << *new_str;
new_str--;
}
cout << *new_str;
}
int main()
{
char *str = new char[1024];
str = "hello world";
reverse(str);
}
当我尝试运行它时,我得到了一些疯狂的输出并且我的计算机开始发出哔哔声。我在这里做错了什么?
【问题讨论】:
标签: c++ string algorithm coding-style reverse