View Single Post
  #3 (permalink)  
Old October 24th, 2004, 10:53 PM
klep klep is offline
Authorized User
 
Join Date: Oct 2004
Posts: 26
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Gill,

Things get a lot easier if you start using the C++ string class instead of C-style character arrays. With the string class, assignment works the way you would expect it to. Since you're passing it into a function, you'd need to pass by reference to get the changes to appear outside the function. The new GetInput() would look like this:

void GetInput(string& name)
{
  cout << "Enter a name :";
  cin >> name;
  name = "John";
  cout << "In function:" << name << endl;
}


----
Scott J. Kleper
Author, "Professional C++"
(Wrox, 2005)
Reply With Quote