![]() |
In C++, we can store the sequence of characters i.e. string in two ways: either as a std::string object or char array. In this article, we will discuss some major differences between string and char[] in C++ Character Array Type StringsA character array is simply an array in C++ that contains characters that are terminated by a null character. Here, characters present in the character array can be accessed by the index of the array. These types of strings are inherited from the C language Syntaxchar str[14] = "GeeksforGeeks"
ExampleC++
Output
GFG is best std::string in C++The std::string is a class that is used to represent strings in C++. They are the modern counterpart of old character array type strings. They contain many different functions to help in string manipulation. Syntaxstring str("GFG is best");
ExampleC++
Output
GFG is best Difference between String and Char[] types in C++The below table lists the major differences between the char[] type and std::string type strings in C++:
|
Reffered: https://www.geeksforgeeks.org
C++ |
Related |
---|
![]() |
![]() |
![]() |
![]() |
![]() |
Type: | Geek |
Category: | Coding |
Sub Category: | Tutorial |
Uploaded by: | Admin |
Views: | 15 |