View previous topic :: View next topic |
Author |
Message |
egon
Joined: 16 May 2004 Posts: 1
|
Posted: Sun May 16, 2004 8:26 am Post subject: streams |
|
|
Hi
I didn't find any examples of stdin and stdout streams so I made one.
Please be free to do whatever you want with it
/Egon |
|
Back to top |
|
|
qbert
Joined: 30 Mar 2004 Posts: 209 Location: Dallas, Texas
|
Posted: Sun May 16, 2004 10:44 am Post subject: |
|
|
Cool!
Im confused though , how the hell does this work
// Convert to upper and print it
output = input.toupper();
??
In std.string toupper is defined as
char[] toupper(char[] s)
After some playing around it looks like all of std.string's functions act as methods on char [] ?!?
It wasn't always this way was it ??
I tried doing this with other objects
Code: |
class xyz { }
char [] convert( xyz a ) {
return xyz.classinfo.name;
}
int main () {
xyz Z;
stdout.writeLine(Z.convert () );
return 1;
}
|
But it didnt take , that would be super cool though.
Charlie |
|
Back to top |
|
|
jcc7
Joined: 22 Feb 2004 Posts: 657 Location: Muskogee, OK, USA
|
Posted: Sun May 16, 2004 11:57 am Post subject: Re: streams example |
|
|
egon wrote: | I didn't find any examples of stdin and stdout streams so I made one. | Thanks. It's a keeper.
Also, I can't figure out how Code: | output = input.toupper(); | works. Perhaps, Walter has been sneaking in undocumented string properties. Did you just guess this would work, or did you see some other code that uses this? |
|
Back to top |
|
|
qbert
Joined: 30 Mar 2004 Posts: 209 Location: Dallas, Texas
|
Posted: Sun May 16, 2004 4:31 pm Post subject: |
|
|
Yes I guess he did, it seems that for all functions expecting char [] as its first argument can be used this way, like stuff in std.conv , std.path , even user defined functions
Code: |
char [] something(char [] x ) {
return x ~ " manipulated";
}
int main()
{
char[] input;
char[] output;
input = "Something";
stdout.writeLine( input.something() );
return 0;
}
|
Its cool! |
|
Back to top |
|
|
jcc7
Joined: 22 Feb 2004 Posts: 657 Location: Muskogee, OK, USA
|
Posted: Sun May 16, 2004 5:15 pm Post subject: |
|
|
This is pretty cool. I wonder exactly how it works. It doesn't seem to work for int (yet?).
Code: | char[] alwaysWhatever(char[] c) {
return "alwaysWhatever" ~ c;
}
int squareit(int i) {
return i * i;
}
void main() {
char[] d = "Hi";
int i = 9;
/* works */
printf("?.*s\n", d.alwaysWhatever());
/* doesn't work... */
//printf("?.*s\t?d\n", d.alwaysWhatever(), i.squareit());
} |
|
|
Back to top |
|
|
|