digitalmars.D - Newbie: Outputting non char types
- matthew_hurne yahoo.com (15/15) Nov 19 2004 As simple as you all probably think this is, I could use a hand...
- J C Calvarese (17/28) Nov 19 2004 If you just want to send text to the screen, I think the best way is
- matthew_hurne yahoo.com (9/39) Nov 19 2004 Thank God, I thought I was going to have to use that doFormat function.....
- Thomas Kuehne (3/6) Nov 19 2004 "%%s" -> "%s"
As simple as you all probably think this is, I could use a hand... First of all, what is the best way to do standard output? I.e. the equivalent of Java's System.out or C++'s cout? Is it writefln? stdout.write()? Or what? Secondly, how can I output simple types such as ints or doubles? I found std.format, but that is a bit over my head at this point, probably because I haven't learned too much about this language yet. But the truth is, if that's how it must be done than I can't see how D is so much easier to use than C++. Please tell me there's an easier way! I did try stdout.write(doubleVar) and it printed junk...probably something to do with "the format is implementation-specific and should only be used in conjunction with read" ... I'm guess that would work fine if I were say, saving these to a file to be read back in later. But I want them output on the terminal. Oh, I'm using Linux, btw. Thanks in advance for any tips. If this is covered at some online tutorial or something and you just want to point me there, feel free!
Nov 19 2004
In article <cnlkrh$qn0$1 digitaldaemon.com>, matthew_hurne yahoo.com says...As simple as you all probably think this is, I could use a hand... First of all, what is the best way to do standard output? I.e. the equivalent of Java's System.out or C++'s cout? Is it writefln? stdout.write()? Or what?If you just want to send text to the screen, I think the best way is writef/writefln in std.stdio.Secondly, how can I output simple types such as ints or doubles? I found std.format, but that is a bit over my head at this point, probably because I haven't learned too much about this language yet. But the truth is, if that's how it must be done than I can't see how D is so much easier to use than C++. Please tell me there's an easier way! I did try stdout.write(doubleVar) and it printed junk...You need to use a format string (%s is a sort of the default specifier)... writefln("%s", i); Here's the nitty-gritty details: http://www.digitalmars.com/d/std_format.html#format-stringThanks in advance for any tips. If this is covered at some online tutorial or something and you just want to point me there, feel free!Here's an example: http://www.dsource.org/tutorials/index.php?show_example=105 By the way, D still has printf. printf isn't as easy to use as writef/writefln, but there are more examples of how to use it out there, such as: http://www.prowiki.org/wiki4d/wiki.cgi?HowTo/printf It's not that I recommend using printf, but if you're having trouble grasping the idea of writef/writefln's format string, printf's format string concept is similar. It might be easier to learn printf just because there are more examples around using it. jcc7
Nov 19 2004
In article <cnlltm$s3k$1 digitaldaemon.com>, J C Calvarese says...In article <cnlkrh$qn0$1 digitaldaemon.com>, matthew_hurne yahoo.com says...Thanks for that tip...As simple as you all probably think this is, I could use a hand... First of all, what is the best way to do standard output? I.e. the equivalent of Java's System.out or C++'s cout? Is it writefln? stdout.write()? Or what?If you just want to send text to the screen, I think the best way is writef/writefln in std.stdio.Thank God, I thought I was going to have to use that doFormat function...when I referred to not understanding something in the above, that's the function I was having trouble with. Sorry that I didn't make the connection that you can use format strings with writef and writefln.Secondly, how can I output simple types such as ints or doubles? I found std.format, but that is a bit over my head at this point, probably because I haven't learned too much about this language yet. But the truth is, if that's how it must be done than I can't see how D is so much easier to use than C++. Please tell me there's an easier way! I did try stdout.write(doubleVar) and it printed junk...You need to use a format string (%s is a sort of the default specifier)... writefln("%s", i);Here's the nitty-gritty details: http://www.digitalmars.com/d/std_format.html#format-stringSo here's a question...what if I wanted to actually output %s? \%s doesn't work...honestly I think this question is pretty irrelevant but I'm curious. :-) Thanks for the help!Thanks in advance for any tips. If this is covered at some online tutorial or something and you just want to point me there, feel free!Here's an example: http://www.dsource.org/tutorials/index.php?show_example=105 By the way, D still has printf. printf isn't as easy to use as writef/writefln, but there are more examples of how to use it out there, such as: http://www.prowiki.org/wiki4d/wiki.cgi?HowTo/printf It's not that I recommend using printf, but if you're having trouble grasping the idea of writef/writefln's format string, printf's format string concept is similar. It might be easier to learn printf just because there are more examples around using it. jcc7
Nov 19 2004
matthew_hurne yahoo.com schrieb am Fri, 19 Nov 2004 20:51:41 +0000 (UTC):So here's a question...what if I wanted to actually output %s? \%s doesn't work...honestly I think this question is pretty irrelevant but I'm curious. :-) Thanks for the help!"%%s" -> "%s" Thomas
Nov 19 2004