11.07.2015 Views

tYSR20

tYSR20

tYSR20

SHOW MORE
SHOW LESS

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

104Part II: Becoming a Functional C++ ProgrammerTable 7-1 (continued)Namevoid strncat(target, source, n)int strnstr(string, pattern, n)OperationConcatenates the source stringonto the end of the target string or‘n’ characters, whichever comesfirst.Finds the first occurrence of onepattern string in another.int strncmp(source1, source2, n) Compares the first n characters intwo strings. Returns a zero if thetwo strings match exactly.int strnicmp(source1, source2)Compares up to n characters intwo strings without regard tocase.You need to add the statement #include to the beginning ofany program that uses a str... function.The current ANSI C++ standard suggests that you avoid the str...() functions.ANSI C++ says that these functions are deprecated, meaning that ANSIwill leave them alone for now, but don’t be surprised if they go away someday. That’s why strings.h uses the older standard of ending all include fileswith a “.h”. The ANSI standard suggests that you use the string type asdefined in the next section. However, you will see a large number of programsthat continue to use these functions.The following Concatenate program inputs two strings from the keyboardand concatenates them into a single string.// Concatenate - concatenate two strings// with a “ - “ in the middle#include #include #include using namespace std;// the following include file is deprecated;// however, it is required for the str functions#include int main(int nNumberofArgs, char* pszArgs[]){// read first string...char szString1[256];cout > szString1;

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!