Variables

Instead of using a string literal to display the message "Hello World" we can use a string variable instead.

1
2
3
4
5
6
7
8
9
10
11
12
// your name
// Good morning!
#include<iostream>
#include<string>
using namespace std;
int main() {
  string greeting="Good morning";
  string students="students";
  cout << greeting<<" "<<students<<endl;
  system("pause");
  return  0;                   
} //main
CODE
Good morning students
Press any key to continue . . .

Notice that we have included the "string" header file,

NEXT: Assignment statements