/* * string2.cpp (sklar/05-apr-2009) * * this program demonstrates passing a string to a function as a * reference parameter. * */ #include #include using namespace std; /* * declare and define the printString() function to display the string * that is passed as an argument to the function */ void printString( string myString ) { cout << "your string = [" << myString << "]" << endl; } // end printString() /* * declare and define the initString() function to initialize the * value of the string */ ////void initString( string myString ) {// doesn't work this way void initString( string &myString ) {// have to do it with & cout << "enter a string: "; getline( cin, myString ); } // end of initString() /** * define main() function */ int main() { // declare string as a local variable string myString; string kelly; // initialize string initString( myString ); initString( kelly ); // now call function to print the string printString( myString ); printString( kelly ); } // end of main()