[cs23021] on character to string initialization and assignment
Mikhail Nesterenko
mikhail at cs.kent.edu
Wed Feb 15 12:53:13 EST 2012
CSI students,
I looked at at firther. A character cannot be assigned to a string at
declaration but _can_ be assigned to a string with regular
assingment. It is a quirk of C++. For example:
// string s1 = 'h'; <--- this is not allowed
string s1 = "h"; // this is legal
s1 = 'h'; // so is this
char mychar='g';
//string s2=mychar; <--- this is not allowed
string s2;
s2=mychar; // however, this is legal
Thanks,
--
Mikhail
More information about the cs23021-2
mailing list