Strings in C++
Strings in C++
Strings in C++ is defined asthe collection of characters is stored in the form of arrays.
C-strings are arrays of type char started with null character, that is \0.
How to define a C-string?
char str[] = "C++";
Alternative ways of defining a string
char str[4] = "C++"; char str[] = {'C','+','+','\0'}; char str[4] = {'C','+','+','\0'};
Program of Strings in C++
#include <iostream> using namespace std; int main() { char str[100]; cout << "Enter first string: "; cin >> str; cout << "You entered: " << str << endl; cout << "\nEnter second string: "; cin >> str; cout << "You entered: "<<str<<endl; return 0; }
Output
Enter first string: Study You entered: Study Enter second string: Study Experts You entered: Study
Read more, Function and array in C++