| |
| Posted by Ilya Minkov in reply to ranjit_bh | PermalinkReply |
|
Ilya Minkov
Posted in reply to ranjit_bh
| ranjit_bh@hotmail.com wrote:
> I have just been introduced to D. But if there is support for c++ why was not the cout or the cin operator not allowed for in D
You can write a library, but you're almost on your own. You can take advantage of D support for standard C runtime, but not C++ which is too clumnsy and not a target for D. We want something more elegant than C++.
I have here an implementation written for an ehanced C compiler supporting operator overloading, which is though incomplete, might give you an idea of how to do it if you like. It was written by the maintainer of LCC-Win32 and only works in it, should requiere a moderate amount of change and refractoring to work in D. HINT: you're not changing this libarary but writing a new one "inspired" by it and the original C++ iostream. :)
For you to get started: the library expects the main application to create the cout buffer. A buffer can either be a file, of a dynamic cstring. If you want it as a file, you open the file as usual and pass it to "iostream_new_from_file(FILE *)". In the case you want it to be a string, you use "iostream_new_from_string(char * buf, int length)". If you pass NULL as buf it shall allocate memory as requiered all by itself. Length limits the length, unless it is 0. This would be simplified in D.
Hope this can be helpful.
-i.
|