Hi to all, i'm italian, and my english is poor ;D
I'm writing a c++ kernel, with a printf function....but i think that i can use streams, like cout<<etc..
i'm searching for a tutorial or some guides about streams and how write a cout, cin function.....
Anyone can help me ?
Use stream instead printf
Re:Use stream instead printf
Hello..
For making cout .. I suggest you to make a printf.. it'll help you..
Now if you have a class called Console with a printf function, then you can have an object cout of this class and you can call it as:
Also you can overload << operator as:
Hope this will help...
For making cout .. I suggest you to make a printf.. it'll help you..
Now if you have a class called Console with a printf function, then you can have an object cout of this class and you can call it as:
Code: Select all
cout.printf("Hello World");
Code: Select all
Console& Console::operator <<(char *string)
{
printf("%s", string);
return *this;
}
Console& Console :: operator << (char c)
{
printf("%c", c);
return *this;
}
Re:Use stream instead printf
That is nice if you already have a functional printf. But if you're starting from scratch, doing a kout is so much easier than a printf with its format string parsing...
Have a look at FirstStep. It's a multiboot kernel that does nothing but print a couple of the multiboot data structures to screen using a kout object.
Have a look at FirstStep. It's a multiboot kernel that does nothing but print a couple of the multiboot data structures to screen using a kout object.
Every good solution is obvious once you've found it.
Re:Use stream instead printf
I think it's an excellent idea, and I did something similar myself. However, the approach I took was to add print and println function to my String class which already had all the << operators and hex conversion etc in place. Then I added sentinel object, such as endl. so
cout << "Num is: " << hex(93) << endl;
... is actually a string object that asks the video driver to print itself whenever it sees a endl token.
There are also explicit print and println methods.
cout << "Num is: " << hex(93) << endl;
... is actually a string object that asks the video driver to print itself whenever it sees a endl token.
There are also explicit print and println methods.