C++ basic review series — sun bujian 1208

C++ basic review series 01 (input/output class, calling mathematical function class)

C++ basics review series 2 (print graphics (loop), classic problems)

C++ basic review series 3 (recursive algorithm) {Fibonacci function, Hanoi issues}

C++ basics review series 4 (summary of scattered data)

C++ basics review series 5

Six, scattered knowledge points

How can I type “\n” cout<<“\n”<<endl;

As for data types, do not blindly int, double and longlong

Strlen () int len=sizeof(a)/sizeof(int);

# define macro definition

Char c = ‘A’; cout << char(c+j%26);

Digital black hole 6174

About utility Functions

  • #include
  • Double floor (double x)
  • Double ceil(double x)
  • #include
  • Isalpha (a[I]) Identifies a letter. Isdigit (a[I]) identifies a number
  • Isupper (a[I]) Determines whether to use upper case. Islower (a[I]) Determines whether to use lower case
  • Isdigit (char c) Function: Checks whether the parameter is a decimal digit character. It is used to check whether c is a digit. If c ranges from 0 to 9, a non-zero value is returned; otherwise, a NULL value is returned. You can loop through an array of characters to determine each item
  • Islower (char c) Function: Checks whether c is a lowercase letter. If c is a lowercase letter, return TRUE. Otherwise, return NULL(0).
  • Isalpha (char c) #include

    Isalpha (char c) #include
  • Isupper (char c) function: Determines whether c is an uppercase letter. If c is an uppercase letter (a-Z), A non-zero value is returned. Otherwise, zero is returned.
  • Int GCD (int a,int b){return b? gcd(b,a%b):a; }
  • LCM = a * b/GCD (a,b)

#include char s[100]; int x=atoi(s); The above two lines also convert s to a number.

String Manipulation: 8 Common String manipulation functions <string.h>

Array assignment: memset(start address, set value, offset, or size x);

1. Puts function — Functions that print strings are typically of the form puts(string group)

Function: Prints a string to a terminal. For example, char a[n] and give the initial value, calls puts(array name) and prints the string.

General form: gets(array of characters)

Action: Input a string from a terminal to an array of characters and get a function value as the starting address of the array. Gets (array name) does the keyboard input. Note: the puts and gets functions can output or input only one string.

3, strcat — the general ‘form of the string concatenation function: strcat(array 1, array 2);

Concatenation: concatenates strings from two string arrays, concatenating string 2 to string 1. Note: The character array 1 must be large enough to hold the concatenated string.

Strcpy (string 1, string 2); strncpy (string 1, string 2)

Char str1[10], str2[]=”DongTeng”; strcpy(str1,str2); The result: str1 is the contents of STR2

Pay attention to

  • A. You cannot assign a string constant or a character array directly to a character array
  • B. Characters at the specified position can be assigned with strncpy. Strncpy (str1, str2, 3); Copy the third character from str2 to str1.

General form: STRCMP (string 1, string 2);

Use: To compare the difference between two strings. There are different rules of comparison.

strcmp(s1, s2); Return 0 if s1 and s2 are the same;

Return less than 0 if s1<s2; Returns a value greater than 0 if s1>s2.

Strlen — a function that measures the length of a string

7. STRLWR function — converts to lowercase function general form: STRLWR (string);

Strupr function — Converts to uppercase function general form: strupr(string). Char s[107]; cin >> s; Enter cine.get (s, 107) when Spaces end; Enter the end of the input input a number after the enter will be entered again when the input character will be carriage return interference so need to solve the problem of eating carriage return for example

 cin>>n;
 char a[100][1000];
 for(int i=0;i<=n-1;i++)
 { cin.get();//吃回车
   cin.get(a[i],1000);}
Copy the code