Hello, I'm creating a string class similar to the format of pascal string or so I heard, the type where the string would not exceed 255 characters. I'm having a bit of problem getting it to the output, how do I pass the entire array, not including the character count at [0] to ostream?
Code:class PascalString { private: unsigned char* data; void copyString(const char* cstr) { int num_char = std::strlen(cstr); if(num_char > UCHAR_MAX) { return; // or abort() where is abort() or exit() in? stdlib.h? } data = new unsigned char[num_char+1]; data[0] = num_char; unsigned char* copier = data[1]; for(int i = 0; i < num_char; ++i) { *copier = cstr[i]; ++copier; } return; } public: PascalString() { data = 0; } PascalString(const char* s) { copyString(s); } friend std::ostream& operator<<(std::ostream& out, const PascalString& ps); }; std::ostream& operator<<(std::ostream& out, const PascalString& ps) { }