tailieunhanh - C++ Timesaving Techniques for Dummies phần 9

Không có vấn đề gì loại ứng dụng bạn đang phát triển, tỷ lệ cược là ứng dụng sẽ có tương tác với Web hoặc với các hệ thống từ xa mà sử dụng giao thức Web. Vấn đề lớn nhất trong giao tiếp với Internet là mã hóa. Mã hóa là quá trình dịch các ký tự có thể được sử dụng trực tiếp | Technique 63 Creating Debugging Macros and Classes are turned off when they do nothing. In programming parlance we say that the program is in debug mode for assert to work and in release mode if asserts are turned off. Let s look at an example of how to use the assert macro in your own code. 1. In the code editor of your choice create a new file to hold the code for the source file of the technique. In this example the file is named although you can use whatever you choose. This file will contain the class definition for your automation object. 2. Type the code in Listing 63-1 into your file. Better yet copy the code from the source file on this book s companion Web site. Listing 63-1 Using the assert Macro include include include int func int v1to10 assert v1to10 1 v1to10 10 - 1 int divisor 0 switch v1to10 case 1 case 2 case 3 case 4 case 5 case 6 case 7 case 8 case 9 case 10 divisor v1to10 2 break int retVal 200 divisor return retVal int main int argc char argv func 3 func 11 return 0 In the listing above our function func accepts an integer value. We expect the input value to be in the range of one to ten inclusive. Values outside of that range will cause a division-by-zero error in the function so we want to make sure that the user doesn t supply such a value. The assert statement shown at the line marked 1 traps for such a condition and exits the program if the value input is outside the specified range. 3. Save the file in the source-code editor and close the editor application. 4. Compile the source-code file with your favorite compiler on your favorite operating system. 5. Run the program on the console window of your favorite operating system. If you have done everything correctly you should see the following output on the console window . assertion v1to10 1 v1to10 10 failed file line 7 Aborted core dumped The output indicates that the assert function triggered and the program exited. The actual text you

TỪ KHÓA LIÊN QUAN