Strings with C and C++

Kom i gang. Det er Gratis
eller tilmeld med din email adresse
Strings with C and C++ af Mind Map: Strings with C and C++

1. A series of bytes that contain the ASCII code for the character to be displayed

1.1. ASCII Code of 1 byte per character

1.2. 1 byte can represent 255 different characters

1.3. Strings are just arrays of base type char

2. <cstring> Declaration and Syntax

2.1. 1. #include <cstring>

2.2. i.e. char str [10] = "Hello!" creates and initializes a char array of size 10 but only uses 7 spaces. or..Hello!\o where \o is a single null terminating character

2.3. char str [] = "Hello!" char *p = "Hello!" These are roughly the same as the others.

3. <cstring> Manipulating Functions in C

3.1. strcpy (s1, s2) - copies s2 to s1, make sure there's room!!

3.2. strcat (s1, s2) - concats s2 to end of s1

3.3. things like char n = 'x' stores numeric ASCII values unlike char *n = "x" which stores the pointer to the address of the array containing x

3.4. strlen (s) - returns size of s not including \o

3.5. strncpy (s1, s2, n)

3.6. strncat(s1, s2, n)

3.7. strncmp(s1, s2, n) - compares s1 and s2 up to n

3.8. cin.getline (variable_Name, size)

3.9. atof() - a function that takes a string and converts it to a floating point value atoi() - a function that takes string and converts to integer

3.10. toupper() - converts one character to upper case tolower() - converts one character to lower case

3.11. strtok (source_String, delimiters) - returns pointer the substring's first appearance strtok (NULL , delimiters) - finds subsequent substrings until reset by new source_String or nullptr

4. MUST have enough space in the C string array to store all chars or else go OUT OF BOUNDS!!

5. <string> Declaration and Syntax

5.1. string string_Name = "literal";

5.2. string string_Name("literal")

6. <string> functions and uses

6.1. = copies

6.2. == compares

6.3. + concats only strings, not cstrings or string literals

6.4. append(str_Name) appends to of current string

6.4.1. add n in () to specify up to how many characters

6.5. str_Name.clear() - clears content of the string, no return value

6.6. str_Name.empty() - returns true of empty, otherwise false

6.7. getline (cin, str_Name)

6.8. str_Name.size() or str_Name.length()

6.9. str_Name.find ("substring", position) returns the location of the first character of the specified substring, optionally start at position

6.10. str_Name.substr (start position, end position)

7. Cstrings and strings can be accessed with array