CharactersAndStrings - itzjac/cpplearning GitHub Wiki

strings

  • This pointer
  • Friend classes
  • Static keyword
  • Namespaces
  • Enumerated Types

Null terminated string

String literals

const char[12]

Escape characters

Backslash + regular character

String functions

Including for the native char string functions.

  • Length
  • Equality
  • Copying
  • Addition

sprintf

transform numbers to Null terminated string

int sprintf(char *buffer, const char* format[,armgument] ...);

std::string

  • Length
  • String Operators (bool comparison)
  • Addition
  • Empty Strings (empty)
  • Substrings (substr)
  • Insertion (insert)
  • Find (find)
  • Replace (replace)
  • Indexing using square brackets
  • Conversion (c_str)
  • getline

EXERCISES

Palindrome

To Upper

To Lower

String reverse

QUIZ

  1. Code analysis strcpy char* x = 0; strcpy(x, "Hello World");

  2. Code analysis find

  3. Size in bytes of a c string

  4. Code analysis static variable in function

    void foo() { static int x = 0;

     x++;
    
     ...
    

    }

  5. How to convert number to string representation

  6. Code Analysis, value of s

    std::string str = "abcdefghijklmnopqrstuvwxyz"; std::string s = str.substr(10, 5);

  7. Code Analysis memory leak with c string char* getString() { char* str = "C++ is fun!";

     return str;
    

    }

  8. Code Analysis strcmp

  9. code analysis This pointer

  10. Code analysis enums