Beefy Boxes and Bandwidth Generously Provided by pair Networks
Do you know where your variables are?

Re: Re: I don't use printf enough

by jryan (Vicar)
on Oct 22, 2003 at 22:08 UTC ( #301396=note: print w/replies, xml ) Need Help??

in reply to Re: I don't use printf enough
in thread I don't use printf enough

I assume you mean:

cout << "text text " << obj.method1() << " more text " << endl;

And would you explain why you find this ironic?

Replies are listed 'Best First'.
Re: Re: Re: I don't use printf enough
by elusion (Curate) on Oct 23, 2003 at 03:00 UTC
    Presumably, he/she finds it ironic beacuse
    cout << "text text " << obj.method1() << " more text " << end1;
    is like using string concatenation in Perl. The root node says to use printf sometimes. printf is a C function, yet it would not be the preferred way of doing things in C.

    So to prefer printf in Perl when something like the above (preferred) C snippet exists, is ironic.

      printf is a C function, yet it would not be the preferred way of doing things in C.

      That's half right - printf is a C function, but it is not preferred in C++. It is preferred in C, of course.

      The reason why printf is not the best way in C++ is that the compiler cannot check the variable types. If you use "%s" to print a string, and then use an integer variable instead, the program crashes at run time. With perl it would just convert the integer into a string and not crash, and with C++ style I/O, it would print the integer as a string. Also, printf cannot be extended to print objects, it is only able to print a few built in types.

Re: Re: Re: I don't use printf enough
by pg (Canon) on Oct 23, 2003 at 03:06 UTC

    His c++ syntax is just fine, his obj can be understood as a pointer to an object:

    #include <iostream.h> class aclass { public: int first_perfect_number(void); }; int aclass::first_perfect_number(void) { return 6; } int main() { aclass * ap = new aclass(); cout << "first perfect number is: " << ap->first_perfect_number() +<< endl; }

      Right, but why on earth would you assume a pointer to an object in this case? The original bit wasn't talking about a reference to a perl object, so I assumed it was a typo. Just because the syntax passes the compiler doesn't mean it is what he meant. :)

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://301396]
[marto]: yes, trying to do anything other than sideload to android via windows has always been more effort than linux
[Corion]: The inconvenient thing is that my Linux machine is in another room than my desktop, so I have to walk up to it while some device is hooked up to it, just to press "allow" for install tasks etc :-)
[Corion]: I see the Chuwi H9 Air, but at the price of 8 or 9 cheapo tablets, that
[Corion]: ... that's not that great for quasi-disposable devices ;)
[Eily]: can't you just remote connect to the linux machine ?
[marto]: IIRC the hiemdal suite made life much easier on windows, and people on XDA developers put out released of windows only pages for adb that made it less of a pain
[marto]: Eily you can't remote connect the physical device via USB ;)
[Corion]: Eily: Sure, that's what I do, but some things you need to do on the Android device directly, like when navigating the bootloader :-)

How do I use this? | Other CB clients
Other Users?
Others lurking in the Monastery: (10)
As of 2018-05-23 09:12 GMT
Find Nodes?
    Voting Booth?