Current location - Plastic Surgery and Aesthetics Network - Plastic surgery and medical aesthetics - How to Convert a String into an Array in c++
How to Convert a String into an Array in c++
C++ converts a string into an array, as follows:

Including? & ltstdio.h & gt

# Contains? & ltstring.h & gt? int? main(void){char? *str? =? “hello world”; Charles? arr _ str[32]; int? Ryan. Me; ? /*? One? Way? */len? =? strlen(str); strncpy(arr_str,? str,? len+ 1); ? For what? (me? =? 0; ? Me? & lt? len? i++)putchar(arr _ str[I]); putchar( 10); ? /*? Another one? Way? */memset(arr_str,0,? sizeof(arr _ str)); Printf ("Please? Input? Answer? String:? " ); scanf("%s ",arr _ str); For what? (me? =? 0; ? Me? & lt? len? i++)putchar(arr _ str[I]); putchar( 10); ? Return? 0; }

Extended data:?

Basic types of C++ language

1, integer

Integer constant

Integer constants are numerical values without decimals, which are used to represent positive and negative numbers. Ox55, 0x55ff and 1000000 in Example 2-2 are all integer constants in c++ language.

There are three forms of integer constants in c++ language: decimal, octal and hexadecimal.

(1) Decimal integers are data consisting of numbers between 0 and 9 that do not start with 0.

(2) Octal integers are data consisting of numbers from 0 to 7 beginning with 0.

(3) Hexadecimal integers are data consisting of numbers from 0 to 9 starting from 0x or 0x and letters from A to F (both uppercase and lowercase letters are acceptable).

Integer variable type

There are four types of integer variables: byte, short, int and long, all of which are signed integer variable types.

(1) byte type.

The byte type describes a signed 8-bit integer variable. Because different machines store multi-byte data in different ways, it may be from low byte to high byte, or from high byte to low byte. In this way, when analyzing network protocols or file formats, it is appropriate to use byte types to represent data in order to solve the problem of byte storage order on different machines.

(2) short type.

The short type describes a signed 16 bit integer variable. The short type limits the storage of data to storing high bytes first, and then storing low bytes.

(3)int type.

The int type describes a signed 32-bit integer variable. Int type is one of the most abundant and effective types. It is most commonly used for counting, array access and integer operation.

(4) long type.

Long describes a signed 64-bit integer variable. For large-scale calculation, large integers beyond the range of int are often encountered, so use long type.

2, floating-point type

Floating point constant

Floating-point numbers are decimal numbers with decimals, which can be expressed by general notation or scientific notation. 0.23f and 0.7e-3 are floating-point constants in c++ language.

(1) General expression: decimal integer+decimal point+decimal point.

(2) Scientific notation: decimal integer+decimal point+decimal point +E (or e)+ symbol+exponent.

Floating point variable type

Floating-point variables, also known as real variables, are used in functional operations that need to be accurate to decimals. There are two types of descriptors, float and double.

(1) floating-point type.

The float type is a 32-bit single-precision floating-point number. It has the characteristics of fast running speed and less space occupation.

(2) double type.

Double type is a 64-bit double-precision floating-point number. On some modern processors with optimization and high-speed operation capabilities, double-precision numbers are faster than single-precision numbers. Double is a double precision type, which has higher precision and larger representation range than single precision type float, and is often used.

3. Character type

Character constant

A character constant is a single character enclosed in single quotation marks.

For example:' a',' a',' z',' $','?' .

Note: "A" and "A" are two different character constants.

In addition to the above-mentioned form of character constants, the c++ language also allows the use of special forms of character constants starting with "\". This character constant is called escape character, which is used to represent some characters that cannot be displayed or have special meaning.

Character variable

The type specifier of the character variable is char, which occupies 8 bits in the machine and ranges from 0 to 255.

Note: Character variables can only store one character, not multiple characters.

3. Boolean type

boolean constant

Boolean constants have only two values: "true" and "false", which mean "true" and "false" respectively. They are both keywords, and the bit length in the machine is 8 bits.

boolean variable

The type specifier of Boolean variables is booI, which is used to represent logical values.

References:

Baidu encyclopedia -C++