How to Declare & Initialise a String in C++

Steps:

  1. Include the necessary header files ( #include<string> ).
  2. Declare a string variable using the std::string type.
  3. Initialize the string variable with the desired value.

For example:

C++




#include <iostream>
#include <string>
 
int main() {
    // Declare and initialize a string
    std::string myString = "Hello, World!";
     
    // Print the string
    std::cout << myString << std::endl;
 
    return 0;
}


Javascript




// Declare and initialize a string
const GFG = "Hello, World!";
 
// Print the string
console.log(GFG);


Output

Hello, World!



How to Declare & Initialise a String in different Programming languages?

To declare and initialize a string in different programming languages, you can use language-specific syntax and functions. Below are examples in C++, C#, Python, JavaScript, and Java, with explanations for each language:

Similar Reads

How to Declare & Initialise a String in C++

Steps:...

How to Declare & Initialise a String in C#

...

How to Declare & Initialise a String in Python

...

How to Declare & Initialise a String in JavaScript

Steps:...

How to Declare & Initialise a String in Java

...