You are on page 1of 1

05 Strings

What’s a string?
In C++, a string is an array of characters. First, we’ll recall how to declare single character
variables in C++, and then we’ll discuss how to declare and initialize strings.
A program that asks the user if he/she is married will most likely store the value of this prompt in
a variable declared as char because [...]
2008 05 25 admin 5.1 Definition Comments (0)
String Examples
Let’s look at a few examples of how strings can be used in programs.
Example 1:
This example program edits a string by changing all spaces with asterisks while also capitalizing
every character in the string. The following function does most of the work:
// edits string by capitalizing all characters and
// replacing spaces with asterisks
void changeCase(char str[])
{
[...]
2008 05 25 admin 5.2 Examples Comments (0)
Using Built-In String Functions
C++ has several standard functions that perform useful string operations. There are many built in
functions; only eleven will be covered in this tutorial. All of the following “built in” functions
are defined in the string.h header file so be sure to include it when using these functions.
strlen
strcpy
strncpy
strcat
strncat
strcmp
strncmp
stricmp
strnicmp
strchr
strlen(string);
Returns the length of a string, not including [...]

You might also like