C++ string and char Data Types

Introduction

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

#include <iostream>
#include <string>
using namespace std;
int main()/*from w w w . j a v a  2 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;
}



PreviousNext

Related