More On C++ Strings: CSIS1117 Computer Programming
More On C++ Strings: CSIS1117 Computer Programming
Contents
c1117 lecture 5
C++ String
c1117 lecture 5
c1117 lecture 5
c1117 lecture 5
c1117 lecture 5
c1117 lecture 5
//
//
//
//
any integers
or false
use double quotes
use single quotes
Constant string 4
"4"
c1117 lecture 5
10
cout
cout <<
<< "continue?
"continue? [y/n]
[y/n] "" <<
<< endl;
endl;
char
char choice;
choice;
cin
cin >>
>> choice;
choice;
cout
cout <<
<< "your
"your choice
choice is
is "" <<
<< choice
choice <<endl;
<<endl;
if(choice
if(choice ==
== 'n'){
'n'){
cout
cout <<
<< "The
"The process
process is
is terminated!"
terminated!" <<
<< endl;
endl;
}}
c1117 lecture 5
11
c1117 lecture 5
are
are
are
are
you
you
y3u
y3u
doing?
doing?
doing?
doing?
output
12
c1117 lecture 5
13
14
unsigned int
c1117 lecture 5
15
unsigned int
c1117 lecture 5
16
c1117 lecture 5
17
attend
attend
lecture
lecture
lecture
lecture
c1117 lecture 5
18
string r = "programming";
int a = r.find("gram");
cout << "a= " << a << endl;
if(r.find("job") == string::npos)
cout << "not a substring!" << endl;
c1117 lecture 5
19
c1117 lecture 5
20
c1117 lecture 5
21
char a, b, c;
cout << "please input some characters: ";
a = getchar(); b = getchar(); c = getchar();
cout << "The first 3 characters are: "
<< a << "," << b << ", and " << c << endl;
please
please input
input some
some characters:
characters: II am
am
The
The first
first 33 characters
characters are:
are: I,
I, ,, and
and aa A space is
also treated
See read-a-char.cc as an example. as a character
c1117 lecture 5
22