Problem:Write a program that uses pointers to write a program that uses pointers to set all elements of an int array to 0.Code:1#include 2 3 using namespacestd;4 5 intMain ()6 {7 Constsize_t Size =5;8 intArr[size] = {0,1,2,3,4};9 for(int*pbegin=arr, *pend =arr+size; Pbegin! = Pend; pbegin++)Ten { One*pbegin =0; A } - for(int*pbegin=arr, *pend =arr+size; Pbegin! = Pend; pbegin++) - { thecout" "; - } - return 0; -}View CodeSummarize:(1) using pointer
The first kind is better and more concise. You can also use the For loop to assign values, but it's tedious.
3.20 read into a set of integers and put them into a vector object, each pair of adjacent integers and output, rewrite the program, this time the first and last output of the sum, and then output the second and the penultimate sum, and so on.void test318 () { int num; vectorvoid test319 () { int num; vector3.21 Please use the iterator to do 3.16 questions.
Problem:Modify the vowel statistics program to make it count the number of spaces, tabs, and line breaks that are read inCode:#include Summarize:(1) The >> input operator of CIN treats null characters (spaces, tabs, and carriage returns) as the end of the input, so special characters such as spaces, carriage returns, and tab are obtained using the Cin.get (ch) method.(2) The case label in the switch statement must be an integer constant expression, and each case statement uses a break to jump ou
¿┌≥æ¿/≠æ¿_≠æ¿?≠æ¿ì≠æ¿æ≠濶£æ¿î£æ¿à£æ¿û£æ¿ Æ¿ Æ¿6 Æ¿g Æ¿z æ¿? æ¿? æ¿ Æ¿á Æ¿î Æ¿ú Æ¿ {J?i686[[em Ailprotected] cpp_src]# This is read out, if it is written, it will lead to a program error, if the use of some mechanisms to bypass the system's restrictions from user space to jump to the kernel space, it can causeThe kernel is not stable.6. Arrays cannot be directly assigned and copiedUnlike vectors, arrays cannot be assigned and copied directly to the whole, which requires attention.There is one
; ABS (a); // --1 return 0;}In the above code, the ABS method is called at 1. Assuming there is no namespace , we know that the system has its own ABS method, then at 1 we are calling the system method, or our own definition of the method? For this ambiguity, C + + provides the concept of a namespace.Namespaces: can help us avoid inadvertent name definition conflicts, and use the same names in the library to cause conflicts.All names defined by the standard library are in the namespace Std.A
Novice C + + when you specify a struct member, you do not know when to use the. operator, and when to use the-I operator.Conclusion: If the structure identifier is a struct name, use the period operator, or if the identifier is a pointer to a struct, use the arrow operator.#include structinflatable{Charname[ -]; floatvolume; DoublePrice ;};intMain () {using namespacestd; intA; Only to keep the DOS interface inflatable*ps=Newinflatable; cout"Enter Name of inflatable item:"; Cin.Get(Ps->name, -
C11: If the parameter type is the same, you can pass a standard library type named Initializer_list, and if the type is different, you can use the Variadic template, see Chapter 16. Here's how to use it:Overloaded version takes only a list of the stringsvoid error_msg (initializer_list3. Function pointersC11 the return type in the tail, as stated below:Use trailing return Typeauto GETFCN (const string), String::size_type (*) (const string, const string );The other two declarations of the functi
comparing their element pairs.3.5 container-sized operationsAll container types provide four container-size-related operations.
The size of the sequential container operation
C.size ()
Returns the number of elements in container C. return type is C::size_type
C.max_size ()
Returns the maximum number of elements that container C can hold, with a return type of C::size_type
C.empty ()
Returns a Boolean value that marks whether
required.Nine, display conversionThe display transformation is called forced type conversion (CAST), which includes the following column name-enforced type conversion operators:Static_cast, dynamic_cast, Const_cast and reinterpret_cast.9.1 When to force type conversionsBecause you want to override the usual standard conversions, you need to show the use of coercion type conversions.Another reason for displaying the use of forced type conversions is that there may be multiple transformations tha
/* Read a piece of text into a vector object, each word stored as an element in the vector, * convert each word in the vector to uppercase. * Output converted elements, one line per 8 words **/#include C + + Primer Fourth Edition exercise--3.14
Throw the question:Attach the code of the example program in the book first#include When the input is normal, there is no problem. When you enter a letter, the word "bad data, try again" is printed, and the effect is as follows:Problem Solving Scenarios:I definitely don't want the results to print indefinitely, and then start looking for reasons, mainly because there's no reason to empty the input stream's buffers. So I made some changes to the program code,#include But this time still can not s
#include If the compiler errorsError: ' strcmp ' is not declared in this scoperesult = strcmp (str1, str2);^Need to add header files C + + Primer Fourth Edition exercise--4.26
: Network Disk DownloadThis book is the prestigious C + + Classic tutorial, the content of C + + master Stanley B. Lippman Rich practical experience and the C + + Standards Committee, the former head of Josée Lajoie to the C + + standard in-depth understanding of the perfect combination, has helped countless programmers around the world to learn C + +. A comprehensive and authoritative description of C + + 's basic concepts and techniques, the emphasis on modern C + + programming style makes thi
Understand:method is called with ().To be more abstract, the method is a variable name, and "()" is a simple representation of the calling method (also for the compiler to recognize), and the calling method is the result of the operation.Eg:a = 1; A is a variable name, and "=" is a simple expression of the assignment (but we have been in touch with the language for too long and the subconscious has assumed that = is the assignment.) But in fact, "=" into the @, replaced by "assignment", and what
answer to its calling function.#include 13. The following is a two function prototype:void Show (double ar[], int n); n is the number of elementsvoid Show2 (double ar2[][3], int n); n is the number of rowsA, write a function call to pass the compound text containing the values 8, 3, 9, and 2 to the function shows ().b, write a function call to pass a compound literal containing 2 rows and 3 columns of value to the function Show2 (), where the first behavior is 8, 3, 9, and the second behavior i
The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion;
products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the
content of the page makes you feel confusing, please write us an email, we will handle the problem
within 5 days after receiving your email.
If you find any instances of plagiarism from the community, please send an email to:
info-contact@alibabacloud.com
and provide relevant evidence. A staff member will contact you within 5 working days.