variable strings in c++ code example

Example 1: how can make string value in cpp

#include <string>
string hello= "hello you thre :)";

Example 2: declaring strings c++

std::string str = "hello world"; 
char *str = "hello world";
char str[] = "hello world"; 
char str[11] = "hello world";

Example 3: c++ strings

#include <iostream>

using namespace std;

void display(char *);
void display(string);

int main()
{
    string str1;
    cout << "Enter a string: ";
    getline(cin, str1);
    display(str1);
    return 0;
}


void display(string s)
{
    cout << "Entered string is: " << s << endl;
}

Tags:

Cpp Example