View Poll Results: Which method do you prefer?

Voters
18. You may not vote on this poll
  • cout << "Hello World!";

    14 77.78%
  • printf("Hello World!");

    3 16.67%
  • system("echo Hello World!");

    0 0%
  • other

    1 5.56%

Best output method

This is a discussion on Best output method within the C++ Programming forums, part of the General Programming Boards category; ^...

  1. #1
    Registered User abrege's Avatar
    Join Date
    Nov 2002
    Posts
    369

    Best output method

    ^
    I am against the teaching of evolution in schools. I am also against widespread
    literacy and the refrigeration of food.

  2. #2
    RoD
    RoD is offline
    Redundantly Redundant RoD's Avatar
    Join Date
    Sep 2002
    Location
    Missouri
    Posts
    6,331
    More a general discussion topic btw:

    cout.

  3. #3
    Banned master5001's Avatar
    Join Date
    Aug 2001
    Location
    Visalia, CA, USA
    Posts
    3,685
    What about write, fprintf, and fwrite?

    Who the hell uses system("echo ...")!? Indeed bad form.

  4. #4
    Just a Member ammar's Avatar
    Join Date
    Jun 2002
    Posts
    953
    I don't think you can compare printf(), and cout, since one is C and the other is C++...
    I think C++ is much better since you don't have problems with data types.
    none...

  5. #5
    Banned master5001's Avatar
    Join Date
    Aug 2001
    Location
    Visalia, CA, USA
    Posts
    3,685
    Lets not get carried away and go around saying stuff like that.

    Example
    Code:
    std::cout << *(std::string *)55 << std::end;
    This will be a problem... Granted you do have to do more work to break cout my example (though extreme) isn't too uncommon.

  6. #6
    moi
    moi is offline
    Registered User moi's Avatar
    Join Date
    Jul 2002
    Posts
    946
    system ("echo ...") makes me barf

    i believe even in C++, printf () has its place, particularly in something that requires heavily formatted output, with bunches of numbers all over the place in different formats. as far as printf () being unsafe, get gcc, it will warn you of printf () and format string not coinciding with passed args at compile time.

    whoever said write and fwrite, they are best used to do other things.
    hello, internet!

  7. #7
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    32,823
    I just use all three
    Code:
    #include <iostream>
    #include <cstdlib>
    using namespace std;
    int main ( ) {
      printf( "%s", cout << system("echo hello world") ? "" : "" );
      return 0;
    }
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.
    I support http://www.ukip.org/ as the first necessary step to a free Europe.

  8. #8
    Banned master5001's Avatar
    Join Date
    Aug 2001
    Location
    Visalia, CA, USA
    Posts
    3,685
    Salem that is the most beautifully written code I've ever seen.

  9. #9
    Just a Member ammar's Avatar
    Join Date
    Jun 2002
    Posts
    953
    Originally posted by moi
    system ("echo ...") makes me barf

    i believe even in C++, printf () has its place, particularly in something that requires heavily formatted output, with bunches of numbers all over the place in different formats
    Can you please explan?
    none...

  10. #10
    moi
    moi is offline
    Registered User moi's Avatar
    Join Date
    Jul 2002
    Posts
    946
    Originally posted by ammar
    Can you please explan?
    exactly what wouldyou like me to explain?
    hello, internet!

  11. #11
    Just a Member ammar's Avatar
    Join Date
    Jun 2002
    Posts
    953
    Sorry it wasn't clear in my furst post, I was in the computer lab in the University, I had a class to catch.
    I want to ask why would we use printf(), to get "formatted output, with bunches of numbers all over the place in different formats"
    none...

  12. #12
    moi
    moi is offline
    Registered User moi's Avatar
    Join Date
    Jul 2002
    Posts
    946
    are you familiar with how to use both printf and ostream (cout, cerr, and friends)?? if not, read something on those first. also, what i said is just my opinion, not fact
    hello, internet!

  13. #13
    Just a Member ammar's Avatar
    Join Date
    Jun 2002
    Posts
    953
    Now it's clear, because I know that everything done by printf(), can be done with cout, and I didn't understand why did you say that, it sounded like a fact, and I was confused...
    none...

  14. #14
    moi
    moi is offline
    Registered User moi's Avatar
    Join Date
    Jul 2002
    Posts
    946
    what i was trying to say is that in such situations, i find printf easier and more sensible to deal with than ostream
    hello, internet!

  15. #15
    Registered User
    Join Date
    Apr 2002
    Posts
    249

    it depends on the program

    it depends on the out put that you want to display on the monitor


    I often use , cout:

    but in some cases I use system (" echo string-out-put"); When I need to show some chioces that the user should read before he typed in his chioce.
    C++
    The best

Page 1 of 2 12 LastLast
Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Help for my output array
    By qwertysingh in forum C Programming
    Replies: 1
    Last Post: 02-17-2009, 03:08 PM
  2. execl()/fork() output
    By tadams in forum C Programming
    Replies: 19
    Last Post: 02-04-2009, 03:29 PM
  3. stuck on display method
    By shintaro in forum C++ Programming
    Replies: 2
    Last Post: 02-01-2009, 05:17 PM
  4. NEED MAJOR HELP WITH HW....Newton-Raphson method
    By clezzie in forum C Programming
    Replies: 8
    Last Post: 04-14-2008, 08:52 PM
  5. Trying to store system(command) Output
    By punxworm in forum C++ Programming
    Replies: 5
    Last Post: 04-20-2005, 07:46 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21