The stream extraction operator (>>
) is overloaded to support string
s. The statements
string stringObject;
cin >> stringObject;
declare a string
object and read a string
from cin
. Input is delimited by whitespace characters. When a delimiter is encountered, the input operation is terminated. Function getline also is overloaded for string
s. Assuming string1
is a string
, the statement
getline( cin, string1 );
reads a string
from the keyboard into string1
. Input is delimited by a newline ('
'
), so getLine
can read a line of text into a string
object. You can specify an alternate delimiter as the optional third argument to getline
.
18.217.68.197