C++ String

Introduction

We can store string literals inside std::string type.

C++ standard library offers a compound type called string or rather std::string as it is part of the std namespace.

We use it for storing and manipulating strings.

C++ Defining a String

To use the std::string type, we need to include the <string> header in our program:

#include <string> 

int main() 
{ 
    std::string s = "Hello World."; 
} 

To print out this string on the standard output we use:

#include <iostream> 
#include <string> 

int main() 
{ 
    std::string s = "Hello World."; 
    std::cout << s; 
} 



PreviousNext

Related