// useful_functions_advanced.h (c) 2000-2001 Kari Laitinen // 22.12.2000 File created. // 06.03.2001 Last modification. // Like file "useful_functions.h", this file contains // general-purporse functions but these functions deal with such // C++ classes as string, stringstream etc. // These functions are thus advanced functions and require the // inclusion of and #ifndef USEFUL_FUNCTIONS_ADVANCED_H #define USEFUL_FUNCTIONS_ADVANCED_H #include #include void capitalize_string( string& given_string ) { // The first letter of given_string will be an // uppercase letter, and subsequent letters will // be lowercase letters. if ( given_string.length() > 0 ) { if ( character_is_letter( given_string[ 0 ] ) ) { given_string[ 0 ] = given_string[ 0 ] & 0xDF ; } unsigned int character_index = 1 ; while ( character_index < given_string.length() ) { if ( character_is_letter( given_string[ character_index ] ) ) { given_string[ character_index ] = given_string[ character_index ] | 0x20 ; } character_index ++ ; } } } int string_to_integer( string& number_as_string ) { stringstream number_as_stream ; int converted_number ; number_as_stream << number_as_string ; number_as_stream >> converted_number ; return converted_number ; } /* The following function is better than cin >> integer_from_user ; because it does not leave any white space characters in the input stream. */ int ask_integer( char text_to_ask_integer_from_user[] ) { cout << text_to_ask_integer_from_user ; string integer_in_string_form ; getline( cin, integer_in_string_form ) ; return string_to_integer( integer_in_string_form ) ; } void stringstream_to_string( istream& given_stringstream, string& given_string ) { // The following function call converts the stream object into // a string object because '\0' is never found in the stream. getline( given_stringstream, given_string, '\0' ) ; } #endif // end of include guard