Primer c++ 5th edition

Start

Types, variables, expressions, statements, functions

init main()
{
  return 0;
}

Function definition: return type, function name, (parameter list), function body

Compile and run the program

translater

input Output

IO mechanism

iostream library

Standard input cin

Standard output cout

Standard error cerr

clog

head File

#include <iostream>

Output operator <<

Accepts two operands, the left side must be an ostream object, and the right side is the value to be printed

Returns the operand on the left

Operator endl ends the current line

std namespace

::Scope operator

Prefix increment operator++

++ val val = val + 1;

for statement

Loop head

Initialization statement (executed only once at the entrance of the for loop), loop condition, expression

Read variable input data

while(std:cin<<val)

Detect std::cin

Use the istream object as a condition to detect the stream state, and when the end of file is encountered, invalid input (not a number)

class

Usually use .h as the suffix of the header file

Use class types that are as natural as built-in types

Sales_item item;

item is an object of type Sales_item, an object of type Sales_item

Member functions: methods

. Members of Class Type Objects

C++ basics

2. Variables and basic types

2.1 Basic built-in types

  1. Arithmetic type

  2. Void type

2.1.1 Arithmetic types

Types of meaning smallest size
bool
char character 8
int Integer
float
Signed and unsigned types

Signed type can represent positive and negative numbers, 0

Unsigned types can only represent numbers greater than 0 unsigned

2.1.2 Type conversion

unsigned char c=-1;

char occupies 8bit, the value of c is 255

Assign an unsigned type a value outside the range, the actual result is the remainder after modulo 256

The first bit of the binary number is the symbol mark

signed char c2=256;

c2 is undefined

When assigning a signed type to a value beyond the range of her representation,

Guess you like

Origin blog.csdn.net/cs18335818140/article/details/108683830