demo-stringh - strcat(first second cout<<"first...

Info iconThis preview shows page 1. Sign up to view the full content.

View Full Document Right Arrow Icon
// Demo of string.h methods #include <iostream> // for cin, cout, endl #include <string.h> // for strlen, strcmp, strcpy using namespace std; int main() { // Some strings for demo char demo[40] = "Short string"; char first[50] = "We\'ll start with this "; char second[25] = "and end with this."; char third[25]; char word1[10] = "orange"; char word2[10] = "blue"; int compareResult; // result of strcmp call // Demo of strlen cout << "Length of demo: " << strlen(demo) << endl; cout << "Length of first: " << strlen(first) << endl; cout << "Length of second: " << strlen(second) << endl; cout << endl; // Demo of string concatentation cout << "first: " << first << "; second: " << second << endl;
Background image of page 1
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: strcat(first, second); cout << "first, after concatenation: " << first << endl; cout << "second, after concatenation: " << second << endl; cout << endl; // Demo of string copying strcpy(third, second); cout << "third: " << third << endl << endl; // Demo of strcmp compareResult = strcmp(word1, word2); if(compareResult < 0) { cout << '\"' << word1 << "\" comes before \"" << word2 << ".\""; } else if(compareResult > 0) { cout << '\"' << word1 << "\" comes after \"" << word2 << ".\""; } else { cout << '\"' << word1 << "\" is the same as \"" << word2 << ".\""; } cout << endl; return 0; }...
View Full Document

This document was uploaded on 02/10/2011.

Ask a homework question - tutors are online