TAILIEUCHUNG - A Complete Guide to Programming in C++ part 16

A Complete Guide to Programming in C++ part 16. This book provides both novice and experienced programmers with a comprehensive resource manual for the C++ programming language. Readers gain experience in all aspects of programming, from elementary language concepts to professional software development, with in depth coverage of all the language elements en route. These elements are carefully ordered to help the reader create useful programs every step of the way. | STANDARD MACROS FOR CHARACTER MANIPULATION 129 The following section introduces macros that classify or convert single characters. The macros are defined in the header files and cctype. Case Conversion You can use the macro toupper to convert lowercase letters to uppercase. If cl and c2 are variables of type char or int where cl contains the code for a lowercase letter you can use the following statement Example c2 toupper ci to assign the corresponding uppercase letter to the variable c2. However if cl is not a lowercase letter toupper cl returns the character as is. The sample program on the opposite page reads standard input converts any letters from lower- to uppercase and displays the letters. As toupper only converts the letters of the English alphabet by default any national characters such as accentuated characters in other languages must be dealt with individually. A program of this type is known as a filter and can be applied to files. Refer to the next section for details. The macro tolower is available for converting uppercase letters to lowercase. Testing Characters A number of macros all of which begin with is. are available for classifying characters. For example the macro islower c checks whether c contains a lowercase letter returning the value true in this case and false in all other cases. Example char c cin c Reads and classifies if isdigit c a character. cout The character is no digit n The following usage of islower shows a possible definition of the toupper macro Example define toupper c islower c c - a A c This example makes use of the fact that the codes of lower- and uppercase letters differ by a constant as is the case for all commonly used character sets such as ASCII and EBCDIC. The opposite page contains an overview of macros commonly used to classify char acters. 130 CHAPTER 7 SYMBOLIC CONSTANTS AND MACROS REDIRECTING STANDARD INPUT AND OUTPUT Sample program A filter that numbers lines. include iostream include .

TỪ KHÓA LIÊN QUAN
TAILIEUCHUNG - Chia sẻ tài liệu không giới hạn
Địa chỉ : 444 Hoang Hoa Tham, Hanoi, Viet Nam
Website : tailieuchung.com
Email : tailieuchung20@gmail.com
Tailieuchung.com là thư viện tài liệu trực tuyến, nơi chia sẽ trao đổi hàng triệu tài liệu như luận văn đồ án, sách, giáo trình, đề thi.
Chúng tôi không chịu trách nhiệm liên quan đến các vấn đề bản quyền nội dung tài liệu được thành viên tự nguyện đăng tải lên, nếu phát hiện thấy tài liệu xấu hoặc tài liệu có bản quyền xin hãy email cho chúng tôi.
Đã phát hiện trình chặn quảng cáo AdBlock
Trang web này phụ thuộc vào doanh thu từ số lần hiển thị quảng cáo để tồn tại. Vui lòng tắt trình chặn quảng cáo của bạn hoặc tạm dừng tính năng chặn quảng cáo cho trang web này.