gogoWebsite

C++ Notes

Updated to 13 hours ago

Notes on chicken, don't spray if you don't like it

1、using namespace std;-----The following semicolon cannot be dropped
usecoutThis statement must be used when
cinCan't enter spaces, usegetchar, call the header file#include<>

2. Cases type conversion such as(int)a, notint(a)

3. Use the integer part(int)3.14

4、if (a>b)There is no colon afterwards, and the conditions should be enclosed in brackets.

When there is more than one if statement block, it should be enclosed with {}.!!!!!!!!!

5. C++ does not need to consider indentation

6. C++ represents cubic root
pow(double x,double y)
For example, if you require a cube root of 9, just pow(9, 1.0/3) or pow(9, (double)3)

7. Float type has 6-bit significant numbers, double type has 15-bit

8. Character constants are in single quotes, such as'a', represents ASCII code 97, which can be directly added and subtracted;

String constants are in double quotes, such as"a", takes up 2 bytes, because the computer needs to be supplemented at the end'\0'The string ending character, whose ASCII code value is 0, indicates an empty operation;

'\101'Indicates characters'A'

9. Symbol constants are defined before the main function and no longer accept any form of assignment, such as
#define PI 3.14#Not lost

When defining a variable, add the keyword const to become a constant variable and cannot be assigned a value, such as
const int a

10. Modular operation%Both sides must be integer data

11、cout<<stew(10)<<aIt is equivalent to putting a in the 10th position and filling it with spaces in front

12. Keep the decimal number of the specified digits:

  1. cout<<setiosflags(ios::fixed)<<setprecision(n)<<a<<endl;n is a decimal digit, follow rounding, if you want to change the conditions, you need tocout<<resetiosflags(ios::fixed);Need to use header files#include<>
  2. usescanfandprintf

13. Enter a character. If it is a capital letter, it will be converted to the corresponding lowercase letter. If it is a lowercase letter, it will be converted to the corresponding uppercase letter. If it is a numeric character, it will be converted to the corresponding numeric value and calculate its square value. If it is not, it will not be converted and the converted result will be output.

#include<iostream>
using namespace std;
int main()
{
	char a;
	cin>>a;
	if(a>='a' && a<='z')
{
		a = a-32;
		cout<<a;
}

	else if(a>='A' && a<='Z')
{
			a= a+32;
			cout<<a;
}

	else if(a>='0' && a<='9')
{
			a = a-'0';			//Number characters to value
			a = a*a;
			cout<<(int)a;		//a is a character type, and to output the value, you must convert it
}

	else
		{cout<<a;}
}

14. For loop: a standard template for looping n times – it should be noted that splitting uses semicolons instead of commas.i++Insteadi=i++

for (i=1; i<=n; i++)
{content;
}

15. There are multiple instances of overloaded function "pow" matching the parameter list:
The overload of the pow function is as follows:

C++ provides the following overload forms of pow functions:

  • double pow(double X,int Y);

    float pow(float X,float Y);

    float pow(float X,int Y);

    long double pow(long double X,long double Y);

    long double pow(long double X,int Y);

When using it, you should set the parameter type reasonably to avoid multiple "pow" instances matching the parameter list.

Among them, the most likely overloading is to use the form:

int X,Y;

num=pow(X,Y);

This is a relatively common function, but the compiler will remind you that multiple "pow" instances match the parameter list.

This problem can be solved using cast type conversion: num=pow((float)X,Y);

16、a=b+cTo output ASCII code value, a must be int, b and c can be characters or a mixture of characters and numbers.