Computer Webmaster Gaming Console Graphics Forum

Welcome to the Computer Webmaster Gaming Console Graphics Forum forums.

You are currently viewing our boards as a guest which gives you limited access to view most discussions and access our other features. By joining our free community you will have access to post topics, communicate privately with other members (PM), respond to polls, upload content and access many other special features. Registration is fast, simple and absolutely free so please, join our community today!

If you have any problems with the registration process or your account login, please contact contact us.

MK PitStop Main Earn $25 Earn Money Posting Extras Members Blogs Image Hosting User Pages
Go Back   Computer Webmaster Gaming Console Graphics Forum > Computer Forums > Software Programming
Register FAQ/Rules Become A V.I.P. Member Search Today's Posts Mark Forums Read

Software Programming Software programming talk, ask questions about computer software programming or help others

Google
Closed Thread
 
LinkBack Thread Tools Display Modes
Old 06-12-2007, 9:39 PM   #1
Alex
 
Alex's Avatar
 
Posts: n/a
My Photos: (0)

Banked:
MK Cash: $

I am Worth:
MK Cash: $
Donate

Recent Blog: None

Default Am I doing this right???

On Mon, 30 Jun 2003 23:54:07 GMT, "Josh Dawg"
<slopeking7@nospam-earthlink.net> wrote:

>I took a C++ turtorial and it said that the coding for displaying text is:
>
>cout<<"what ever you want to write";
>
>but it won't work for me, is there something wrong in the coding or is my
>compiler messed up?


I can't believe no one hit this obvious problem:

cout is within the namespace std - your problem is that you should
have written:

#include <iostream>

int main()
{
std::cout << "whatever you want to write" << std::endl;
//the std::endl may not be necessary (it skips a line and forces cout
//to display (iirc))

//you can avoid writing std:: before every command if you type
//using namespace std; right after the #include statement but
//that's bad programming practice - a better way might be to
//type using std::cout; and using std::endl; - now your only line of
//code can be:
// cout << "whatever you want to write" << endl;

return 0;
}


Alex
atheist #2007
 
Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Spurl this Post!Reddit!
Advertisements
Old 06-12-2007, 9:39 PM   #2
Eternal Vigilance
 
Eternal Vigilance's Avatar
 
Posts: n/a
My Photos: (0)

Banked:
MK Cash: $

I am Worth:
MK Cash: $
Donate

Recent Blog: None

Default Am I doing this right???

whoever thought that stream style's format was an improvement over good ole
printf()
must of been either smoking something or trying to justify their job.

Alex wrote:

> On Mon, 30 Jun 2003 23:54:07 GMT, "Josh Dawg"
> <slopeking7@nospam-earthlink.net> wrote:
>
> >I took a C++ turtorial and it said that the coding for displaying text is:
> >
> >cout<<"what ever you want to write";
> >
> >but it won't work for me, is there something wrong in the coding or is my
> >compiler messed up?

>
> I can't believe no one hit this obvious problem:
>
> cout is within the namespace std - your problem is that you should
> have written:
>
> #include <iostream>
>
> int main()
> {
> std::cout << "whatever you want to write" << std::endl;
> //the std::endl may not be necessary (it skips a line and forces cout
> //to display (iirc))
>
> //you can avoid writing std:: before every command if you type
> //using namespace std; right after the #include statement but
> //that's bad programming practice - a better way might be to
> //type using std::cout; and using std::endl; - now your only line of
> //code can be:
> // cout << "whatever you want to write" << endl;
>
> return 0;
> }
>
> Alex
> atheist #2007


 
Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Spurl this Post!Reddit!
Old 06-12-2007, 9:39 PM   #3
Alex
 
Alex's Avatar
 
Posts: n/a
My Photos: (0)

Banked:
MK Cash: $

I am Worth:
MK Cash: $
Donate

Recent Blog: None

Default Am I doing this right???

On Wed, 02 Jul 2003 07:34:41 GMT, Eternal Vigilance <wotan@oneeye.com>
wrote:

>whoever thought that stream style's format was an improvement over good ole
>printf()
>must of been either smoking something or trying to justify their job.


Are you able to overload printf() so that you can do the following
(real question since I never used "good ole printf()" since it was
before my time)?

myClass myObject;
//assign values to myObject's members here

cout << myObject;

============== SCREEN RESULTS
my1stVar = 32
my2ndVar = The rain in Spain is wet.
my4thVar = -2



Alex
atheist #2007
 
Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Spurl this Post!Reddit!
Old 06-12-2007, 9:39 PM   #4
Eternal Vigilance
 
Eternal Vigilance's Avatar
 
Posts: n/a
My Photos: (0)

Banked:
MK Cash: $

I am Worth:
MK Cash: $
Donate

Recent Blog: None

Default Am I doing this right???

look up the function its in <stdio.h>

int printf( const char *format [, argument]... );

^^^^^ format string can be a Var itself so you can change
the format in program......

printf("text %d <- int %s<- string %x<- int as hex <cr><lf> ---> \n",
var1,string,var2);


fprintf similar but to a file......
sprintf similar but outputs to a char array (string)


I use them mostly for building error strings for output or logfile entries
(shorter and more readable codewise)
(like another poster said it is a bit slower than explicit string building
itoa() strcat() etc.... )

you could use printf in your overloaded << operator to output what you want
for object data dump



sprintf(&outstr[0]," Object[%d] X=%f Y=%f Z=%f HP=%d /n",
objx->index, objx->xPos, objx->yPos, objx->zPos, objx->HP);

outstr[] contains:
Object[23] X=4.3434 Y=56.5555 Z=1.0000 HP=100


Alex wrote:

> On Wed, 02 Jul 2003 20:34:59 GMT, "Tony Di Croce"
> <iaretony@hotmail.com> wrote:
>
> >No, but to be fair, you had to OVERLOAD the operator... The implementation
> >is somewhere...

>
> Yes, that's the core of my question: can you overload printf()?
>
> Alex
> atheist #2007


 
Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Spurl this Post!Reddit!
Old 06-12-2007, 9:39 PM   #5
Kemal Enver
 
Kemal Enver's Avatar
 
Posts: n/a
My Photos: (0)

Banked:
MK Cash: $

I am Worth:
MK Cash: $
Donate

Recent Blog: None

Default Am I doing this right???

www.dcs.shef.ac.uk/~u0ke
"Alex" <support@microsoft.com> wrote in message
news:7n68gvo0r88itqlk8k5j2isc61682hdj94@4ax.com...
> On Thu, 03 Jul 2003 10:46:56 GMT, Eternal Vigilance <wotan@oneeye.com>
> wrote:
>
> >you could use printf in your overloaded << operator to output what you

want
> >for object data dump

>
> But could you do printf(myObject); and print out the member variables
> in a nice little format?
>
>
> Alex
> atheist #20


Are you trying to do something like in java wher eyou can overload an
objects 'toString()' method? i.e myObject.printf()?

--
Kemal Enver
u0ke@dcs.shef.ac.uk


 
Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Spurl this Post!Reddit!
Old 06-12-2007, 9:40 PM   #6
Alex
 
Alex's Avatar
 
Posts: n/a
My Photos: (0)

Banked:
MK Cash: $

I am Worth:
MK Cash: $
Donate

Recent Blog: None

Default Am I doing this right???

On Thu, 3 Jul 2003 22:10:13 +0100, "Kemal Enver" <kemalenver@f2s.com>
wrote:

>Are you trying to do something like in java wher eyou can overload an
>objects 'toString()' method? i.e myObject.printf()?


I'm asking if it's possible. Not sure about the Java.

In the end I don't really need to know, I'm just exploring the
advantages of cpp's cout << as opposed to the printf() function. I'm
not even sure if this is the best advantage - it probably isn't -
since I know close to nothing about C.


Alex
atheist #2007
 
Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Spurl this Post!Reddit!
Featured Websites
Free Space
Free Space
Free Space Free Space
Closed Thread
Tags: ,




Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Featured Websites




All times are GMT +1. The time now is 12:40 AM.


Powered by: vBulletin Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
LinkBacks Enabled by vBSEO 3.0.0
Cheap Computers
MK PitStop Copyright 2005 - 2008

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98