eyesofhope wrote: |
---|
As for your code, I'm not accustomed to not "using namespace std" I don't understand it very well with all of the "std::"s around. we haven't been using iterators yet, but if you have a link to a guide on them, I would appreciate it. Also, I'm pretty sure we're not supposed to push anything... we're supposed to send a new string back to the main function. |
I'll tell you what my code does.
Reverse() is a function that returns a
std::string, and takes a
std::string object as an argument (called
String). Pay no attention to the ampersand (&) for the moment.
The
const_iterator is an iterator (look at the bottom of this post, marked A) that's used to pass through
String. The iterator was set to the end of
String (point B). I then declared another
std::string object called
Out, which will store the string that will be given back to
main().
for Loop, Condition: While
Itor is not at point A of
String.
for Loop, Increment/Decrement: Decrements
Itor (moving towards point A).
While the
for loop's condition is false, the character pointed to by
Itor is added to the end of
Out.
When the loop is finished,
Out is returned.
A) Without going into depth, an iterator is an object that moves from 1 point to another. An array, for example, has a point A (the first element) and a point B (the last element). An iterator would move from point A to point B. The value of an iterator is the element the iterator refers to.
Also, the
std:: is an alternative, as well as
using std::cout, for
using namespace std;. What's the difference?
using namespace std causes name conflicts, and destroys the purpose of
namespaces (a simple topic, but I won't explain them here).
Wazzak