// Fig. 16.11: getquery.cpp // Demonstrates GET method with XHTML form. #include using std::cout; #include using std::string; #include int main() { string nameString = ""; string wordString = ""; string query = getenv( "QUERY_STRING" ); // output header cout << "Content-type: text/html\n\n"; // output XML declaration and DOCTYPE cout << "" << ""; // output html element and some of its contents cout << "" << "Using GET with Forms" << ""; // output xhtml form cout << "

Enter one of your favorite words here:

" << "
" << "" << "" << "
"; // query is empty if ( query == "" ) cout << "

Please enter a word.

"; // user entered query string else { int wordLocation = query.find_first_of( "word=" ) + 5; wordString = query.substr( wordLocation ); // no word was entered if ( wordString == "" ) cout << "

Please enter a word.

"; // word was entered else cout << "

Your word is: " << wordString << "

"; } cout << ""; return 0; } // end main /************************************************************************** * (C) Copyright 1992-2003 by Deitel & Associates, Inc. and Prentice * * Hall. All Rights Reserved. * * * * DISCLAIMER: The authors and publisher of this book have used their * * best efforts in preparing the book. These efforts include the * * development, research, and testing of the theories and programs * * to determine their effectiveness. The authors and publisher make * * no warranty of any kind, expressed or implied, with regard to these * * programs or to the documentation contained in these books. The authors * * and publisher shall not be liable in any event for incidental or * * consequential damages in connection with, or arising out of, the * * furnishing, performance, or use of these programs. * *************************************************************************/