Difference Between string and char[] Types in C++ Last Updated : 09 Oct, 2024 Comments Improve Suggest changes Like Article Like Report 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 languageSyntaxchar str[14] = "GeeksforGeeks"Example C++ // C++ Program to show the use of character array type strings #include <iostream> using namespace std; int main() { // Character array char str[14] = "GeeksforGeeks"; // Print each character in the array for (int i = 0; i < 13; i++) { cout << str[i]; } return 0; } OutputGeeksforGeeksstd::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");Example C++ // C++ Program to show the use of std::string #include <iostream> using namespace std; int main() { // Sample string string str("GFG is best"); // Print the string cout << str; return 0; } OutputGFG is bestDifference 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++:std::string in C++Character Array in C++It does not contains '\0' at the end.It contains '\0' at the end.There is no need to worry about memory managementIf allocated on stack, the memory remains fixed. If allocated on heap, user have to manually manage the memory.Represented as the objects of std::string objects and are also implement internally using character arrays.Directly implemented and represented as character arrays.Have some associated function to help in string manipulation.No associated functions. String manipulation is done by using the explicitly defined functions in <string.h> header.It is defined in the <string> header in C++It is the part of the language.Only works in C++.Works in both C and C++. Comment More infoAdvertise with us Next Article Difference Between string and char[] Types in C++ S satwiksuman Follow Improve Article Tags : C++ Programs C++ cpp-data-types cpp-string cpp-array CPP Examples +2 More Practice Tags : CPP Similar Reads What is the Difference Between C++ String == and compare()? In C++ == and compare() both are used to compare strings and find if the given strings are equal or not but they differ in working. In this article, we will learn the key differences between == and compare() of string in C++. "==" Operator in C++The == operator in C++ is used to compare two strings 3 min read Difference Between Array of Characters and std::string in C++ In C++, we have character array and std::string class both of which are used to store the sequence of characters. The character arrays are a part of C-style programming on the other hand std::string is a part of the C++ standard library. In this article, we will discuss what are some major differenc 3 min read Difference Between Null Strings and Empty String in C++ In C++, we generally initialize a string that does not store anything at declaration as either a null string or an empty string. They both may seem similar to each other but they are different in terms of what they store or refer to. In this article, we will discuss the key differences between the n 3 min read Difference Between Pointers and Array Notations in C++ In C++, pointers and array notations are two ways using which we work with arrays and memory for accessing the data. They have distinct behaviours and are used in different contexts. In this article, we will learn the key differences between pointers and array notations in C++. Difference Between Po 4 min read Difference Between std::wstring and std::string The std::wstring and std::string are the classes in C++ used to store sequences of characters. While serving similar purposes, they serve different requirements. In this article, we will look at some major differences between the std::wstring and std::string in C++. Wide String in C++The std::wstrin 3 min read Difference between cout and puts() in C++ with Examples Standard Output Stream(cout): The C++ cout statement is the instance of the ostream class. It is used to display output on the standard output device which is usually the display screen. The data needed to be displayed on the screen is inserted in the standard output stream (cout) using the insertio 2 min read Convert String to Char Array in C++ In C++, we usually represent text data using the std::string object. But in some cases, we may need to convert a std::string to a character array, the traditional C-style strings. In this article, we will learn how to convert the string to char array in C++.ExamplesInput: str = "geeksforgeeks"Output 4 min read Convert character array to string in C++ This article shows how to convert a character array to a string in C++. The std::string in c++ has a lot of inbuilt functions which makes implementation much easier than handling a character array. Hence, it would often be easier to work if we convert a character array to string. Examples: Input: ch 4 min read Convert char* to std::string in C++ Strings are generally represented as an instance of std::string class in C++. But the language also supports the older C-Style representation where they are represented as array of characters (char* or char[]) terminated by null character '\0'. In this article, we will learn how to convert the char* 3 min read How to Convert a std::string to char* in C++? In C++, strings are the textual data that is represented in two ways: std::string which is an object, and char* is a pointer to a character. In this article, we will learn how to convert a std::string to char* in C++. Example Input:string myString = "GeeksforGeeks";Output:char * myString = "Geeksfor 1 min read Like