CS253

CS253: Software Development with C++

Spring 2018

String Literals

See this page as a slide show

String Literals

CS253 String Literals

Literals

String Literals

A "string literal" is an anonymous array of characters. These are equivalent:

cout << "abc123" << '\n';
abc123
const char make_up_a_name[] = "abc123";
cout << make_up_a_name << '\n';
abc123
const char make_up_a_name[] = "abc123";
const char *p = &make_up_a_name[0];
cout << p << '\n';
abc123

Comparing C-Style Strings

if ("beta" < "alpha")   // BAD CODE
    cout << "This is really quite surprising!\n";
c.cc: In function 'int main()':
c.cc:1:14: warning: comparison with string literal results in unspecified 
   behavior
This is really quite surprising!

Comparing C-style strings properly.

Comparing C++ std::strings

    < > <= >= == !=

Modified: 2017-12-29T23:16

User: Guest

Check: HTML CSS
Edit History Source
Apply to CSU | Contact CSU | Disclaimer | Equal Opportunity
Colorado State University, Fort Collins, CO 80523 USA
© 2015 Colorado State University
CS Building