Professional Documents
Culture Documents
C++ Week 10 - New
C++ Week 10 - New
C++ Week 10 - New
Week 10
String class
Note
• Property: 屬性
• Concatenate: 連接
• Provides: 提供
Outline
• String class
• String class declaration and initialization
• String library
• length
• substr
• find
• insert
• compare
• replace
• Practice
String class
• cin: used for strings that "do not contain '\n', '\t', and space
key characters". Space keys can be used to separate different
inputs.
• getline: Used for strings that "contain the whitespace key
character, '\t'". Only the newline key can be used to separate
different inputs.
Cin and getline
• split
Input is a string str, a character c, str must contain the c character,
please use the c character as the boundary to cut the str string and
output it in a new line.
example:
intput:
abc/def/ghi
/
output:
abc
def
ghi
Practice
Input:
we promptly judged antique ivory buckles for the next prize
output:
pangrams
input:
we promptly judged antique ivory buckles for the prize
output:
Not pangram
Practice
Input:
3
abcdde
baccd
eeabg
Output:
2