diff --git a/lectures/01_introduction/README.md b/lectures/01_introduction/README.md index 0eb86d8..49fadfe 100644 --- a/lectures/01_introduction/README.md +++ b/lectures/01_introduction/README.md @@ -255,7 +255,7 @@ the order and types of the parameters in the function prototype. ## 1.13 Python Strings vs. C chars vs. C-style Strings vs. C++ STL Strings - Strings in Python are immutable, and there is no difference between a string and a char in Python. Thus, ’a’ and "a" are both strings in Python, not individual characters. In C++ & Java, single quotes create a character type (exactly one character) and double quotes create a string of 0, 1, 2, or more characters. -- A “C-style” string is an array of chars that ends with the special char ’\0’. C-style strings (char* or char[]) can be edited, and there are a number of helper functions to help with common operations. +- A “C-style” string is an array of chars that ends with the special char ’\0’. C-style strings (char\* or char[]) can be edited, and there are a number of helper functions to help with common operations. - The “C++-style” STL string type has a wider array of operations and functions, which are more convenient and more powerful. ## 1.14 About STL String Objects @@ -287,23 +287,27 @@ object. There are several ways of constructing string objects: The STL streams std::cin & std::cout are used to read data from and write data to the "console". Often, we would rather read data from a file and/or write the output to a file. We can do this using the STL file stream library fstream. And here is an [example program](getline.cpp). Actually, this example program is the starting point to most of your homeworks. It shows how you can read information from a file, and write information into another file. -## 1.16 Two Useful String Functions +# 1.16 String Concatenation + +The `+` operator can be used to concatenate `std::string` objects or a `std::string` with a C-style string. + +```cpp +#include +#include + +int main() { + std::string str1 = "Hello"; + std::string str2 = "World"; + std::string result = str1 + " " + str2; // Concatenation + std::cout << result << std::endl; // Output: Hello World + return 0; +} +``` + +## 1.17 Two Useful String Functions - find() - substr() This [example program](strings.cpp) which uses these two string functions, can also be very useful in your homeworks. -