// String functions
#include <iostream.h>
#include <string.h> // definitions
main()
{
// Definition and initialization of string variables
// --> Sec. 5.1
char s[30], s1[30] = "Hello", s2[] = "World";
int i;
cout << "s1 = " << s1 << endl;
cout << "s2 = " << s2 << endl;
i = strcmp(s1,s2); // lex. comparison
cout << "cmp : " << i << endl;
strcpy(s,s1); // copy s1 on s
cout << "s : " << s << endl;
strcat(s,s2); // Appends s2 on s
cout << "s : " << s << endl;
i = strlen(s); // length of string s
cout << "Length of s : " << i << endl;
}
|
Details über diese Funktionen (und weitere) können mittels
LINUX> man 3 string
LINUX> man strcmp
erhalten werden.