summaryrefslogtreecommitdiffstats
path: root/main.cpp
blob: 607b40c3f770dd47ffaa5f9800afd7a69d1a2be9 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
#include "string.h"

int main(int argc, char **argv)
{
    MyString mystr("alpha");
    if (mystr.isSubstring("ph"))
    {
        std::cout << "true" << std::endl;
    }
    else
        std::cout << "false" << std::endl;

    /* uses copy ctor, compiler implicitly creates obj out of ", beta" and
     * then passess it to copy ctor
     */
    MyString mystr1 = ", beta";
    /* next to call ctor that takes in char arr */
    MyString mystr2("charlie"); /* if it was () then it would be a fwd decl! */
    MyString mystr3 = MyString(", delta");

    mystr.concat(mystr1).concat(mystr2).concat(mystr3);
    std::cout << mystr << std::endl;

    MyString mystr4 = "hello";
    mystr4.concat(", world!").concat(" goodbye");
    std::cout << mystr4 << std::endl;

    /* test outward conversion */
    const char *mystr_charptr = mystr4;
    std::cout << mystr_charptr << " | len: " << std::strlen(mystr_charptr) << std::endl;

    MyString mystr5 = "bro";
    std::cout << mystr5 << ", char at 1 is: " << mystr5[1] << std::endl;

    /* getCount() is a static method hence it doesn't need to be called on
     * an object
     */
    std::cout << "mystring instances count: " << MyString::getCount();

    return 0;
}