-
Notifications
You must be signed in to change notification settings - Fork 0
/
string.cpp
36 lines (31 loc) · 1001 Bytes
/
string.cpp
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
33
34
35
36
#include <iostream>
#include <string>
// void PrintString(std::string string) // Copy string => Too slow!
// void PrintString(const std::string string) // Use reference
void PrintString(const std::string &string) // Use reference and const
{
// string += " copy"; // You do not modify (Recommend)
std::cout << string << std::endl;
}
int main()
{
std::string name = "Minho"; // + " hello!";
name += " hello!";
// PrintString(name);
name.size();
bool isThereHo = name.find("ho") != std::string::npos;
std::cout << isThereHo << std::endl;
std::cout << name << std::endl;
char litheralName[] = "Minho";
litheralName[2] = 'm';
std::cout << litheralName << std::endl;
const char *multipleLine = R"(Line1
Line2
Line3)";
std::cout << multipleLine << std::endl;
const char *multipleLine2 = "Line1\n"
"Line2\n"
"Lin23\n";
std::cout << multipleLine2 << std::endl;
return 0;
}