Hi, I am new to C++. I'm trying to reverse a word input, but I've done something wrong, and it is not couted correctly. It can, however, cout each character, so I am not sure where I have gone wrong. Also, whenever I use a string type pointer, the program crashes.
Ah, you're right about the indexing. I should have caught that. It should be
1 2
string* reverse = new string[word.size()];
char* reverse = newchar[word.size()];
and
for (i = 0, j = word.size()-1; i<=word.size()-1; i++,j--)
and
reverse[word.size()]='\0';
Though when I try it with type string, I am still getting a crash. (The debugger lists only the address for reverse when it is pointing to string memory.) EDIT: Now I see the error of my ways: my code preallocates an array of strings, and that string allocation is much different.