Arrays
Examples of String Processing
#include <iostream.h>
/* This is an example of string I/O in C++ */
int main()
{
char String[80];
int i;
cout << "Enter string: ";
cin >> String;
cout << "String: " << String << endl;
exit(0);
}
#include <iostream.h>
/* This is an example of string handling in C++ */
int main()
{
char string[] = "Hello World";
int i;
for(i=0; string[i] != '\0'; i++)
cout << "Element " << i << " of the array is " << string[i] <<
endl;
cout << "\nThe string array is: " << string << endl;
exit(0);
}
#include <string.h>
#include <iostream.h>
/* An example of string functions */
int main()
{
char in_string[80], copy_string[80];
for(int i=0;cin.get(in_string[i]);i++);/* read in string from std.
input */
strcpy(copy_string, in_string);/* copy in_string to copy_string */
if ( strlen(copy_string) > 80 ) /* check the length of copy_string
*/
cout << "Final string is too long\n";
else
cout << "The copied string is:\n" << copy_string << "\n";
exit(0);
}
Back to Previous Page
Document:
Local Date:
Last Modified On: