Javatpoint Logo
Javatpoint Logo

C++ Strings

In C++, string is an object of std::string class that represents sequence of characters. We can perform many operations on strings such as concatenation, comparison, conversion etc.


C++ String Example

Let's see the simple example of C++ string.

Output:

Hello
C++

C++ String Compare Example

Let's see the simple example of string comparison using strcmp() function.

Output:

What is my favourite fruit? apple
What is my favourite fruit? banana
What is my favourite fruit? mango
Answer is correct!!

C++ String Concat Example

Let's see the simple example of string concatenation using strcat() function.

Output:

Enter the key string: Welcome to
Enter the buffer string:  C++ Programming.
Key = Welcome to C++ Programming.
Buffer =  C++ Programming.

C++ String Copy Example

Let's see the simple example of copy the string using strcpy() function.

Output:

Enter the key string: C++ Tutorial
Key = C++ Tutorial
Buffer = C++ Tutorial

C++ String Length Example

Let's see the simple example of finding the string length using strlen() function.

Output:

Length of String = 26




Please Share

facebook twitter google plus pinterest tumbler

Latest 4 Tutorials