<cstring>strlen(cstring) find out the string length of
the cstringstrcpy(target, src) copy the the src
(a C-string) to the the target= to copy strings. target is
large enough to hold the value of the srcstrncpy(target, src, int limit) similar to strcpy,
but at most
limit characters are copied. It is safer than strcpy.
#include<iostream> |
strcpy to copy strings.
#include<iostream> |
#include<iostream> |
strcpy does not check to make sure the array is large
enough to hold all the characters.
#include<iostream> |
strncpy to make sure that the string is big enough
for all the characters.
#include<iostream> |
Absol |
strcat(target, src) concatenates(appends) the src
to the end of the target.target is large
enough to hold the the result. strncat(target, src, int limit): similar to strcat,
but at most
limit characters are appended.
#include<iostream> |
| Hello! Charles |
strcmp(string1, string2) compares 2 strings.
string1 is same as string2
string1 is smallar than string2,
i.e. if string1 and string2 are put in a
dictionary, string1 appears first.string1 is greater than string2.strncmp(string1, string2, int limit), similar to strcmp(string1,
string2)
but only compare at most limit characters.
#include<iostream> |
Please input 2 words |
Please input 2 words |
cin >> charArray
cin.getline(stringName, max_characters + 1)It reads
max_characters and copy the data to stringName
#include<iostream> |
Please enter your name: Amy
Hello! Amy
|
Please enter your name: Charles Li
Hello! Charles
|
getline to input a whole line.
#include<iostream> |
Please enter your name: Charles Li
Hello! Charles Li
|
Please enter your name: abcdefghijklmnopqrstuvwxyz
Hello! abcdefghijklmnopqrs
|
#include<cctype>toupper(char ch) or (tolower(char ch))
returns the uppercase (or lowercase) version of the character ch.
The function
won't change the argument ch islower(char ch), isupper(ch), isdigit(ch), isalnum(char),
isspace(ch), ispunct(ch):
returns ture or false, the meaning should be clear. islower(ch)
returns true is ch is a lowercase letter. Refer to the
book for the definitions of other functions.
#include<iostream> |
Your input: 314159
The input is a number.
|
Your input: 3445ab33
The input is not a number.
|