1. The handling of line breaks when Cin reads errors1#include 2 3 using namespacestd;4 5 intMain () {6 DoubleD;7 CharC;8CIN >>D;9 if(!cin) {Tencout "x"Endl; One cin.clear (); Acout Get() Endl; - } - //cin.get (); theCin.Get(c); -}The above code input is divided into 2 cases:If the input is a double type, cin.get (c) reads the newline character and the program finishes running.If the input is not a double type, such as the char type, then CIN will place the wrong bit, leaving
C + + is a programming language developed on the basis of C language, which integrates object-oriented programming, general programming and traditional procedural programming, which is a superset of C language. The C + + Primer Plus (6th edition) (Chinese version) was written in accordance with the 2003 Iso/ansi C + + standard. The basic concepts and techniques o
be shared between files, and the internal name of the link is shared only by functions in one file.3. Using the keyword register, it is recommended that the compiler use CPU registers to store automatic variables, which are designed to increase the speed of accessing variables. (Same as the previous usage of auto, c++11 obsolete).4. Static storage persistence variables provide 3 features: external linkage (external declaration of code blocks), internal chaining (code block external static decla
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
18 key notes for C ++ Primer Plus 6th, primerplus
The following are the notes I have taken after reading C ++ Primer Plus version 6th, which can be used as a memorandum for future review.Note Section
Why is the const of C ++ bet
Here are the notes I made after reading the 6th edition of C + + Primer Plus, as a memo to facilitate review later.Notes section
Why is C + + const better than C # # #?
First, it can explicitly specify a type and have type checking capabilities.Second, you can restrict a definition to a specific function or file by using a scope rule for C + +.Thi
. precompilation pre-compile the command after # for example iostream to compile the contents of Ioistream after replacing # with the writing of large code files into a compound file.9. Above iostream if you need to have a. h suffix in C + + in C + + if you use the old header file in C, you can still use the. h extension But some files are removed by the. h extension and preceded by a prefix c for the file name to represent the header file library from the C language. For example, using MATH.H i
Programs and programming are more interesting when you use the bootstrapper to select statements for different actions. C + + provides an if statement, if Else statement, and a switch statement to manage options. An If statement enables a program to execute a statement or block of statements conditionally, that is, if a specific condition is met, the program executes a specific statement or block of statements. The IF Else statement program chooses to execute one of two statements or blocks of s
C ++ Primer Plus 6th Reading Notes, primer6th1. Handling line breaks when cin reads errors
1 # include
The preceding code is entered in two cases:
If the input is double type, cin. get (c) will read the line break and the program is running.
If the input is not double type, such as char type, the cin will set the error bit, retain the incorrect input while d
Learning Summary1, the circulation of the grammar and other languages are not bad, probably most of the language on the basis of the development of C, so much the same is not strange.2, in the judgment expression, only 0 of C language is considered false, all non-0 value positive integers are considered true.1 #include Operation Result:1 is True-1 is True3, the For loop has three expressions, the first expression to initialize the counter, the second expression to express restrictions on the com
1. Procedural programming and object-oriented programming2. Abstraction and Class1. Programs that use class objects can access the public part directly, but only through public member functions (or friend functions) to access the private members of the object2. You can define a member function outside of a class declaration and make it an inline function3. Constructors and destructors for classes1. A constructor that accepts a parameter allows an object to be initialized to a value using the ass
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, -
-programreturn valueParametersPrivate variables in sub-programsVariable-length parameter listImproved max sub-programEmpty argument listAbout lexical (my) variablesUse strict compilation instructionsreturn operatorEllipsis and numberNon-scalar return valuePersisting private variablesExercisesFifth chapter input and outputReading standard inputInput from the diamond operatorCalling parametersOutput to standard outputjnprintf formatted outputArrays and printfFile handleOpen File HandleRead and wri
Again see for Beginners C + + people recommend C + + primer I will beat people, really!By his mother, this gang of forced to mislead, delayed countless kung fu!is to listen to these silly rumors, said C + + primer explain more in-depth what, beginners should also chew this book, I bought this C + + primer paper books, the computer also has English electronic vers
a const variable and that the variable must be initialized. You might say that this const is not the same? constexpr is more rigorous, the expression used to initialize the variable must be a ' constant expression ' . This means that the constexpr variable is a const variable initialized by a constant expression . As for the constant expression, we'll talk about it later, for the basic data type, the constant expression is a literal constant, a variable that constexpr the limit, and a cons
C ++ Primer Plus Chapter 1 question solution, primer Chapter 2
Chapter C ++ Primer Plus
# Include
Using namespace std; double fun (double x, double y); int main () {cout
7-2
#include
using namespace std;int input(double *a);void output(double *a, int n);double
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.