C++: The string class

This entry is part 8 of 61 in the series C++

To make it easier to handle string, the standard C++ library provides a string class.

To include the string class, we need to have this line #include <string> at the header of the file.

#include <iostream>
#include <string>
using namespace std;

void main()
	string str;

	cout << "Please enter your name\n";
	cin >> str;

	cout << "Hello, " << str << "!\n";



The operator << is an output operator. cout is the standard output stream.  It is used to output a string of characters.

The operator >> (“get from”) is used as an input operator; cin is the standard input stream.


Series Navigation<< C++: Printing the ASCII value of a char
C++: A string class and its method >>
Posted in

Leave a comment

Leave a Reply