The string and char Data Types - C++ STL

C++ examples for STL:string

Introduction

A string can consist of zero, one, or more characters.

Demo Code

#include <iostream>
#include <string>
using namespace std;
int main()/* w  w  w .  j  a  va2 s .c  o m*/
{
   int value;
   string message;
   cout << "Enter a number: ";
   cin  >> value;
   cout << "The number entered is:\n" << value << endl;
   cout << "Enter text:\n";
   getline(cin, message);
   cout << "The text entered is:\n" << message << endl;
   cout << int(message.length());
   return 0;
}

Result


Related Tutorials