View Single Post
Old 06-28-2005, 11:26 PM   #5 (permalink)
redhead
Newbie
 
redhead's Avatar
 
Join Date: Jun 2002
Location: Denmark
Posts: 1,726
redhead is on a distinguished road
You might be refering to this thread where you would parse by reference instead of making copies like your swap function does.
Which would alter your code to be:
Code:
#include <iostream>
#include <string>

namespace stacy
{
  //swap() swaps string1 and string2, then prints the new values.
  void swap(std::string &string1, std::string &string2)
  {
    std::string holder;
    holder = string1;
    string1 = string2;
    string2 = holder;
    std::cout << "String 1 is now '" << string1 
                  << "' and string 2 is '" << string2 << "'." 
                  << std::endl;
    }
}



int main()
{
  std::string one = "one";
  std::string two = "two";
  std::cout << "Befor swap: " << one << " " << two << std::endl;
  stacy::swap(one, two);
  std::cout << "After swap: " << one << " " << two << std::endl;
  std::cin.get();
}
__________________
Don't worry Ma'am, We're university students, We know what We're doing.
-----
If you pull the pin, Mr.Grenade would no longer be your friend.
-----
01000111 01101111 00100000 01000011 00100000 00100001
redhead is offline   Reply With Quote