Return Styles: Pseud0ch, Terminal, Valhalla, NES, Geocities, Blue Moon. Entire thread

I made a booboo

Name: Anonymous 2009-09-29 0:50

Anyone know how to fix this lump of shit to reverse a text string?  Fffuuuck

#include <iostream>
#include <string>

using namespace std;

string reverse(string& str);

void writeBackward(string s, int size)
{
   if (size > 0)
   {  // write the last character
      cout << s.substr(size-1, 1);
 
      // write the rest of the string backward
      writeBackward(s, size-1);  // Point A
   }  // end if
 
   // size == 0 is the base case - do nothing
}  // end writeBackward
int main()
{
    string s = "Hello there";
cout << "s has " << s.length() << " characters." << endl;
   string theString = "";

   cout << "Enter a (backward) string: ";
   getline(cin, theString);

   cout << reverse(theString) << endl;

   return 0;
}  // end main

string reverse(string& s, int size)
{
   
   // Implement me!!!
}  // end reverse

Name: Anonymous 2009-09-29 0:58


string reverse(string& s) {
  string t = "";
  for (const_reverse_iterator<char> iterator = s.const_reverse_iterator.rbegin(); iterator != s.const_reverse_iterator.rend(); iterator++) {
    t += *iterator;
  }
  s = t;
}

Name: Anonymous 2009-09-29 1:10

string reverse(string& s)
  {
    string t;
    for (const_reverse_iterator<char> iterator = s.const_reverse_iterator.rbegin(); iterator != s.const_reverse_iterator.rend(); ++iterator)
      {
        t += *iterator;
      }
    return t;
  }

Name: Anonymous 2009-09-29 1:42

string reverse(string& s)
      {
        if (s.length() == 0)
            return s;
        else
          {
            return s[s.length()-1] + reverse(s.substr(0, s.length() - 1));
          }
      }

Newer Posts
Don't change these.
Name: Email:
Entire Thread Thread List