problem: Write a main function main, use two values as arguments, and output their and.Code:#include Settings in vs2012: Results:Command-line invocation:C + + Primer (fourth edition) after class exercise 7.15 main function parameter
; //Decltype (a) c = A; c is of type int, and a is the initial value of CDecltype ((b)) d = A; D is the int type and is a reference++c; The value after ++c is 4;++d; The value after ++d is 4Exercise 2.37Q: Assignment is a class of typical expressions that generate references, and the type of reference is the type of the left value. That is, if I is an int, the type of the expression i=x is int. The type of the following variables is indicated according to this feature.A:int A = 3, b = 4; A, b ar
---restore content starts---Problem:The program connects two C-style string literals and stores the results in a C-style string literal.Code:#include Summarize: (1) A dynamic array, using the new expression and having [], must use the delete expression and have [] disposed.(2) strcpy and strcat The first argument must be an array pointer.C + + Primer (fourth edition) after class exercise 4.30
base class name with a scope character that describes the member to invoke the base class at. A base-class version member that is hidden in a derived class exists, is only hidden, and cannot be called through a derived class object.Therefore, the underlying cause of the hidden (different scope) rule is actually the C + + name resolution process (that is, the first member of the name is found in the derived class domain, and if it is stopped, it will continue to be looked up in the base class fi
#include Note: Programs that use C-style strings need to manage the allocation and release of memory themselves . instead, use the string typeProgram is automatically allocated and freed by the system, so it is shorter than the program using C-style strings,The execution speed is also a bit faster.C + + Primer Fourth Edition exercise--4.28
/* Read a piece of text into a vector object, each word stored as an element in the vector, * required to be implemented with an iterator that converts each word in the vector into uppercase letters. * Output converted elements, one line per 8 words **/#include C + + Primer Fourth Edition exercise--3.17 (Redo 3.14)
function . In this case, the return type of main is int, and the return value of 0 is indeed a value of type int. extension: If the function does not need a return value, only void is used. If you need to end the function with a return, you do not need to follow the argument after return. Example: // There is a return type int getsum (int A, int b) { return a + b; } // no return type void Myprint () {std::cout this is test " Std::endl; return ;//This return statement may no
the built-in logical and, logical, or comma operators are not guaranteed to be evaluated.
Class members and non-member overloaded operatorsOverloaded unary operator If there is no (explicit) parameter as a member function, there is a formal parameter as a non-member function. Similarly, the overloaded two-tuple operator has a formal parameter when defined as a member, and two parameters when defined as a non-member function.
The principle of setting an operator to a class member or a no
set to friend.
Set a function template as FriendTemplate std::ostream operatorTemplate Friend Class queueNeeds access to item and nextFriend std::ostreamoperator// ...};Template Needs access to headFriend std::ostreamoperator};
Member templatesAny class (template or non-template) can have itself as a member of a class template or function template, a member of which is called a member template, and the member template cannot be virtual.
Defining member templates outside of a classWhen a m
of 3 years is:"return 0;}7#include structcar{Charmake[ +];intyear;};intMain () {using namespaceStdintNum Car * cars; cout "How many cars does you wish to catalog:"; CIN >> Num; Cars =NewCar[num]; for(inti =0; i "Car #"1":\ n"; cout "Please enter the Make:";//cin >> cars[i].make;Cin.getline (Cars[i].make, +); Cin.get (); cout "Please enter the year made:"; Cin >> Cars[i].year; } cout "Here is your collection:\ n"; for(inti =0; i " "Delete[] cars;return 0;}8#include #include i
calculated from the lowest bit.Here's another example: int main () {bitset 5 > Bitobj (12 ); cout ENDL; cout 0 ]ENDL; cout 1 ]ENDL; cout 2 ]ENDL; cout 3 ]ENDL; cout 4 ]ENDL; return 0 ;} The result of the execution is:[Email protected] cpp_src]# g++ test.cpp [[email protected] cpp_src]#. /a. Out0110000110 From the above results, the subscript operation of the Bitset is counted starting from 0, and is the lowest bit of bitset, which is counted from the lowest to
operator, however, means that the original address (arr[2]) is de-referenced instead of the incremented new address, so the value of *pt++ is arr[2], or 25.4,However, the value of PT will be the address of arr[3] When the statement is executed.#include"stdafx.h"#includeintMain () {using namespacestd; Doublearr[5]={21.1,32.8,23.4,45.2,37.4}; Double*pt=arr; ++pt; intA; Doublex; coutEndl; coutEndl; coutEndl; coutEndl; X=*pt++; coutEndl; CIN>>A;}Note: The pointer increment and decrement follow the
of 3 years is:"return 0;}7#include structcar{Charmake[ +];intyear;};intMain () {using namespaceStdintNum Car * cars; cout "How many cars does you wish to catalog:"; CIN >> Num; Cars =NewCar[num]; for(inti =0; i "Car #"1":\ n"; cout "Please enter the Make:";//cin >> cars[i].make;Cin.getline (Cars[i].make, +); Cin.get (); cout "Please enter the year made:"; Cin >> Cars[i].year; } cout "Here is your collection:\ n"; for(inti =0; i " "Delete[] cars;return 0;}8#include #include i
, Reinterpret_castReinterpret_cast usually provides a mechanism for the re-interpretation of the bitwise patterns of the operands.For example: int IVar; int *pint = IVar; 12345; char *pch = reinterpret_castchar *> (PINT);Here, if we access the memory through a PCH, the system interprets the memory 4 bytes (32bit system) of the variable Ivar as a char array; it is noteworthy that Ivar and *pint accessThis area of memory will still be interpreted as an int, which means that the mandatory
data to the file string str ; Ifile>>str ; //read data from a file: As with CIN, you encounter a blank getline (ifile,str ); Span class= "Hljs-comment" >//the file that is associated with the file input stream is read into a line to str coutstr ; //output to standard output device Note: After opening the file, remember to check whether the open is successfulif (!ifle)//If unsuccessful then prompt. In addition, once the fstream is open, it remains associated with the specified file, to as
This chapter is a simple overview, exercise content is easy, so only a few knowledge points, do not put the exerciseCIN >> A returns the left operand, which is: Cin (IStream), and the input stream is false only if EOF or illegal input is encountered (such as the input int, but a long long number is entered).EOF on Windows is control + Z, which is control + D on Mac OSX or UNIX.Code style is a variety of, but we should choose the time should adhere to and perfect, as far as possible to read a hig
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.