Strings

A String is an array of characters; like a word or a sentence.

Here’s an example:


#include <iostream>

using namespace std;

int main()
{
 //Declare string size 100.
 char string[100];

 //Prompt user to input a word.
 cout << "Please enter a word." << endl;

 //Reads input, store in string, \n waits for user to push enter.
 cin.getline(string, 100, '\n');

 //Outputs first character in string.
 cout << "Your word started with a: " << string[0] << endl;
 cin.get();
}

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s