-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathstrings.cpp
More file actions
32 lines (22 loc) · 901 Bytes
/
strings.cpp
File metadata and controls
32 lines (22 loc) · 901 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
#include <iostream>
using namespace std;
int main() {
cout << "This is a string" << endl;
cout << "\"To be or not to be\" - a string with quotes" << endl; // \ is the escape character
cout << "This is a string with a newline\n" << endl;
const char* my_c_style_str = "This is a C-style string"; // this produces a warning
cout << my_c_style_str << endl;
string my_string = "This is a C++ string";
cout << my_string << endl;
cout << endl;
string my_2nd_string = " - which is cool";
cout << my_string + my_2nd_string << endl;
auto foo = "foo - a C++ string object"s;
auto bar = "bar - a C-style string";
cout << foo << endl << bar << endl << endl;
cout << "Size of foo, a string object, is " << sizeof(foo) << endl;
cout << "Size of bar, a const char*, is " << sizeof(bar) << endl;
string chant = "Let's go Red Sox!";
cout << chant << endl;
return 0;
}