36 lines
1.1 KiB
C++
36 lines
1.1 KiB
C++
|
#include <iostream>
|
||
|
#include <cstring>
|
||
|
#include "String.hh"
|
||
|
|
||
|
int main() {
|
||
|
String str("Blubaloo");
|
||
|
std::cout << "String '" << str.data() << "' is " << str.length() << " chars long." << std::endl;
|
||
|
|
||
|
|
||
|
// Chain Assignment
|
||
|
std::cout << "String assignment" << std::endl;
|
||
|
String a, b;
|
||
|
a = b = String("Empty");
|
||
|
std::cout << "String '" << a.data() << "' is " << a.length() << " chars long." << std::endl;
|
||
|
std::cout << "String '" << b.data() << "' is " << b.length() << " chars long." << std::endl;
|
||
|
|
||
|
|
||
|
// Operator+
|
||
|
std::cout << "Operator +" << std::endl;
|
||
|
a = String("Loose") + String(" Statement");
|
||
|
std::cout << "String '" << a.data() << "' is " << a.length() << " chars long." << std::endl;
|
||
|
|
||
|
|
||
|
// Operator+=
|
||
|
std::cout << "Operator +=" << std::endl;
|
||
|
b += " " ; // String takes a const char* as input to constructor, so autoconversion available
|
||
|
b += a ;
|
||
|
std::cout << "String '" << b.data() << "' is " << b.length() << " chars long." << std::endl;
|
||
|
|
||
|
// Type Conversion
|
||
|
std::cout << "Type Conversion" << std::endl;
|
||
|
String c("Almost Empty");
|
||
|
|
||
|
std::cout << "String '" << c.data() << "' is " << strlen(c) << " chars long." << std::endl;
|
||
|
}
|