Strings

Objectives

We would like to :
  1. Investigate both C and C++ strings.

Notes

  • char word[] = "the string";
  • char * word = strdup("the string");
  • In general a c style string is an array of characters.
  • Manipulation of strings is most commonly done with a library function.
  • #include <string.h> or #include <cstring>
  • reference.
  • In modern usage c style strings are discouraged.
  • But at times you will need these
  • C++ style strings
  • Some helpful character functions
    • reference.
    • From #incldue <cctype> ,
    • is*
    • to*
    • All take an int and return an int.
    • But they are really character.
  • >>, and getline with strings
  • A word of caution
    • Linux terminates lines in a file with \n
    • Windows terminates lines in a file with \r\n
    • c/c++ only expects \n
    • dos2unix and unix2dos