Strings

Over the tutorials or as you've been learning C++ you will probably have come accross strings. This tutorial is for anyone who hasn't - strings are very useful - they store strings of characters (hence the name), they can be resized (unlike arrays of chars) and have a few functions that allow them to be quite useful.

#include <string> 		// This includes the string class
/* As strings are in the namespace std you must either use std::string
or "using namespace std;" at the start of the document */
using namespace std;

string name = "Peter";	// Give the string some information

int main(){
	name.length();	// Return's the string's length
	name[2] = 'y';	// Changes the third character to 'y' (starts at 0)
	name.push_back('c');	// Adds one character to the end - c
	name.append(" surname");	// Adds the text to the string
	cout << "My name is " << name ;	// Displays the string
	return 0;
}
If you would like to get in contact, please email me at:
conn_peter@hotmail.com