Results 1 to 29 of 29

Thread: How do I make this more efficient?

  1. #1

    Thread Starter
    KrisSiegel.com Kasracer's Avatar
    Join Date
    Jul 2003
    Location
    USA, Maryland
    Posts
    4,985

    How do I make this more efficient?

    Code:
    #include <iostream>
    
    int main()
    {
            std::cout << "Hello World!" << std::endl;
    }

  2. #2
    I'm about to be a PowerPoster! mendhak's Avatar
    Join Date
    Feb 2002
    Location
    Ulaan Baator GooGoo: Frog
    Posts
    38,170
    Code:
    #include <iostream>
    
    int main()
    {  
    cout << "Hello World!"; 
    }


    ???

  3. #3
    Frenzied Member Acidic's Avatar
    Join Date
    Sep 2003
    Location
    UK
    Posts
    1,090
    I've only ever used C++ years ago, I've never known it well by any means. But I never used std::.
    I can't remember for sure, but isn't something else included at the top, presumably so you don't always can to type std::
    Have I helped you? Please Rate my posts.

  4. #4

    Thread Starter
    KrisSiegel.com Kasracer's Avatar
    Join Date
    Jul 2003
    Location
    USA, Maryland
    Posts
    4,985
    Originally posted by mendhak
    Code:
    #include <iostream>
    
    int main()
    {  
    cout << "Hello World!"; 
    }


    ???
    That isn't more efficient

    endl flushes teh buffer. Also, you didn't use std:: or using namespace so your code won't compile
    Originally posted by Acidic
    I've only ever used C++ years ago, I've never known it well by any means. But I never used std::.
    I can't remember for sure, but isn't something else included at the top, presumably so you don't always can to type std::
    std:: is better than using namespace std;. This way, I can have functions named cout and other stuff named the same as what std has.

  5. #5
    Hyperactive Member spoiledkid's Avatar
    Join Date
    Oct 2002
    Location
    Canada
    Posts
    437
    I do not think you need to type that, it should work without that thing. std stands for standard output .....

  6. #6

    Thread Starter
    KrisSiegel.com Kasracer's Avatar
    Join Date
    Jul 2003
    Location
    USA, Maryland
    Posts
    4,985
    Originally posted by spoiledkid
    I do not think you need to type that, it should work without that thing. std stands for standard output .....
    Um no, std is the namespace in whcih the functions are in. If you used a deprecate header like <iostream.h> then you don't need it, but with the new header style <iostream> you do.

    If you try to compile without using std and the new header style, the compiler will have no clue where the function cout and endl are located

  7. #7
    VBA Nutter visualAd's Avatar
    Join Date
    Apr 2002
    Location
    Ickenham, UK
    Posts
    4,906

    Re: How do I make this more efficient?

    Originally posted by kasracer
    Code:
    #include <iostream>
    
    int main()
    {
            std::cout << "Hello World!" << std::endl;
    }
    Write it in C
    Code:
    #include <stdio.h>
    
    int main(void)
    {
            puts ("Hello World");
    
            return 0;
    }
    PHP || MySql || Apache || Get Firefox || OpenOffice.org || Click || Slap ILMV || 1337 c0d || GotoMyPc For FREE! Part 1, Part 2

    | PHP Session --> Database Handler * Custom Error Handler * Installing PHP * HTML Form Handler * PHP 5 OOP * Using XML * Ajax * Xslt | VB6 Winsock - HTTP POST / GET * Winsock - HTTP File Upload

    Latest quote: crptcblade - VB6 executables can't be decompiled, only disassembled. And the disassembled code is even less useful than I am.

    Random VisualAd: Blog - Latest Post: When the Internet becomes Electricity!!


    Spread happiness and joy. Rate good posts.

  8. #8
    Kitten CornedBee's Avatar
    Join Date
    Aug 2001
    Location
    In a microchip!
    Posts
    11,594
    Why would you want it more efficient?

    If you really want, you can write it directly to the buffer, but...
    All the buzzt
    CornedBee

    "Writing specifications is like writing a novel. Writing code is like writing poetry."
    - Anonymous, published by Raymond Chen

    Don't PM me with your problems, I scan most of the forums daily. If you do PM me, I will not answer your question.

  9. #9
    Frenzied Member Memnoch1207's Avatar
    Join Date
    Feb 2002
    Location
    DUH, Guess...Hint: It's really hot!
    Posts
    1,861
    here you go
    More efficient AND managed code!
    Code:
    using System;
    
    class Class1
    {
         public static void Main()
         {
              Console.WriteLine("HELLO WORLD");
         }
    }
    Being educated does not make you intelligent.

    Need a weekend getaway??? Come Visit

  10. #10
    Frenzied Member
    Join Date
    Aug 2000
    Posts
    1,539
    USE NAME SPACE STD DAMN MEnDHAK

    Code:
    #include <iostream>
    using namespace std;
    int main()
    {
            cout << "Hello World!" << endl;
    }

  11. #11
    Kitten CornedBee's Avatar
    Join Date
    Aug 2001
    Location
    In a microchip!
    Posts
    11,594
    Managed code is never more efficient.
    C# might be shorter, but this code isn't.
    All the buzzt
    CornedBee

    "Writing specifications is like writing a novel. Writing code is like writing poetry."
    - Anonymous, published by Raymond Chen

    Don't PM me with your problems, I scan most of the forums daily. If you do PM me, I will not answer your question.

  12. #12
    Hyperactive Member VBD's Avatar
    Join Date
    Apr 2001
    Location
    The Place Above The Place Below Heavin
    Posts
    278

    Write it ASM

    Sorry, I don't know asm
    Hello

  13. #13

    Thread Starter
    KrisSiegel.com Kasracer's Avatar
    Join Date
    Jul 2003
    Location
    USA, Maryland
    Posts
    4,985
    Originally posted by CornedBee
    Why would you want it more efficient?

    If you really want, you can write it directly to the buffer, but...
    This thread was a joke to break the forum in. However, how exactly would you write directly to the buffer?
    Originally posted by Memnoch1207
    here you go
    More efficient AND managed code!
    Code:
    using System;
    
    class Class1
    {
         public static void Main()
         {
              Console.WriteLine("HELLO WORLD");
         }
    }
    Eww hell naws. Mine will atleast compile on linux

  14. #14
    Fanatic Member alkatran's Avatar
    Join Date
    Apr 2002
    Location
    Canada
    Posts
    860
    QBasic:


    VB Code:
    1. Print "HELLO WORLD!"


    It doesn't get much shorter than that.
    Don't pay attention to this signature, it's contradictory.

  15. #15
    Retired VBF Adm1nistrator plenderj's Avatar
    Join Date
    Jan 2001
    Location
    Dublin, Ireland
    Posts
    10,359
    Originally posted by kasracer
    Mine will atleast compile on linux
    mono
    Microsoft MVP : Visual Developer - Visual Basic [2004-2005]

  16. #16
    Kitten CornedBee's Avatar
    Join Date
    Aug 2001
    Location
    In a microchip!
    Posts
    11,594
    You can access the stream buffer using the rdbuf member function. Then you can use its functions to write directly, avoiding all the formatting and checking stuff that the ostreams do.
    All the buzzt
    CornedBee

    "Writing specifications is like writing a novel. Writing code is like writing poetry."
    - Anonymous, published by Raymond Chen

    Don't PM me with your problems, I scan most of the forums daily. If you do PM me, I will not answer your question.

  17. #17
    VBA Nutter visualAd's Avatar
    Join Date
    Apr 2002
    Location
    Ickenham, UK
    Posts
    4,906
    Originally posted by alkatran
    QBasic:


    VB Code:
    1. Print "HELLO WORLD!"


    It doesn't get much shorter than that.
    That would make it less efficient though.
    PHP || MySql || Apache || Get Firefox || OpenOffice.org || Click || Slap ILMV || 1337 c0d || GotoMyPc For FREE! Part 1, Part 2

    | PHP Session --> Database Handler * Custom Error Handler * Installing PHP * HTML Form Handler * PHP 5 OOP * Using XML * Ajax * Xslt | VB6 Winsock - HTTP POST / GET * Winsock - HTTP File Upload

    Latest quote: crptcblade - VB6 executables can't be decompiled, only disassembled. And the disassembled code is even less useful than I am.

    Random VisualAd: Blog - Latest Post: When the Internet becomes Electricity!!


    Spread happiness and joy. Rate good posts.

  18. #18
    Addicted Member Osiris's Avatar
    Join Date
    Oct 2000
    Location
    Dimension Hole
    Posts
    142
    I'll give it a try...

    Code:
    #include<iostream.h>
    
    int main()
    {
          cout << "Hello World!\n";
    
          return 0;
    }
    i think this would be the code for assembly.

    Code:
    .model     SMALL
    .stack      64
    .data
    
    msg      DB      "Hello World!", 0Ah, 0Dh, '$'
    
    .code
    
    MAIN      PROC      FAR
    
          MOV      AX, @DATA
          MOV      DS, AX
    
          MOV      AH, 09H
          LEA      DX, msg
          INT      21H
    
          MOV      AH, 4CH
          INT      21H
    
    MAIN      ENDP
    END      MAIN
    ؊Ϯϊ

  19. #19
    Kitten CornedBee's Avatar
    Join Date
    Aug 2001
    Location
    In a microchip!
    Posts
    11,594
    DOS assembly...
    All the buzzt
    CornedBee

    "Writing specifications is like writing a novel. Writing code is like writing poetry."
    - Anonymous, published by Raymond Chen

    Don't PM me with your problems, I scan most of the forums daily. If you do PM me, I will not answer your question.

  20. #20

  21. #21
    Frenzied Member dis1411's Avatar
    Join Date
    Mar 2001
    Posts
    1,048
    using just the necessary cout code instead of the entire header

    also maybe feeding the ascii values instead of a string would be faster

    no way im gonna look it up tho..

  22. #22
    Kitten CornedBee's Avatar
    Join Date
    Aug 2001
    Location
    In a microchip!
    Posts
    11,594
    The "necessary" cout code is quite a lot: The complete definitions of basic_ostream, basic_ios, ios_base, basic_ostreambuf and a few other minor things.

    And feeding ASCII values makes no difference.
    All the buzzt
    CornedBee

    "Writing specifications is like writing a novel. Writing code is like writing poetry."
    - Anonymous, published by Raymond Chen

    Don't PM me with your problems, I scan most of the forums daily. If you do PM me, I will not answer your question.

  23. #23
    Frenzied Member dis1411's Avatar
    Join Date
    Mar 2001
    Posts
    1,048
    Originally posted by CornedBee
    And feeding ASCII values makes no difference.
    y is this? are they converted when compiling the prog?

  24. #24

    Thread Starter
    KrisSiegel.com Kasracer's Avatar
    Join Date
    Jul 2003
    Location
    USA, Maryland
    Posts
    4,985
    Originally posted by dis1411
    y is this? are they converted when compiling the prog?
    Why do you think feeding it ascii values would speed it up? A string is made up of ascii values.....

  25. #25
    Frenzied Member dis1411's Avatar
    Join Date
    Mar 2001
    Posts
    1,048
    b/c SOMETHING has to convert the letters to their respective ascii values

    is this case youre the one who's doing it, not the computer

    however, if the compiler converts them for u, it wouldnt make a difference when the program is run
    Last edited by dis1411; Dec 26th, 2003 at 03:32 PM.

  26. #26
    Kitten CornedBee's Avatar
    Join Date
    Aug 2001
    Location
    In a microchip!
    Posts
    11,594
    Actually the operating system converts the scan codes from your keyboards to the ASCII values that your text editor inserts into the program source code. It's the text editor (or the OS) that has to convert the ASCII codes to the character glyphs so you can see them.

    So many people, even among programmers, simply don't know or realize that there is no difference to a computer between characters and their ASCII codes except in usage - and that is up to the programmer to decide. To the computer, it's all just numbers.
    All the buzzt
    CornedBee

    "Writing specifications is like writing a novel. Writing code is like writing poetry."
    - Anonymous, published by Raymond Chen

    Don't PM me with your problems, I scan most of the forums daily. If you do PM me, I will not answer your question.

  27. #27
    Frenzied Member Magiaus's Avatar
    Join Date
    Mar 2002
    Location
    swamp land
    Posts
    1,267
    Ok,as far as topic asm is the most effeciant. What I really wanted to say though is is it just me or is MartinLess well more of of a dork then a programmer has a right to be. No offence Martin but was it nessecary to talk about the topic title and what if I want to use [ c o d e ] and [ / c o d e] tags because I'm posting non VB code?

    I wish I had my asm code resources I can put out Hello World out in three lines of asm if I remember right..
    Magiaus

    If I helped give me some points.

  28. #28
    Former Admin/Moderator MartinLiss's Avatar
    Join Date
    Sep 1999
    Location
    San Jose, CA
    Posts
    33,431
    Originally posted by Magiaus
    ...What I really wanted to say though is is it just me or is MartinLess well more of of a dork then a programmer has a right to be. No offence Martin but was it nessecary to talk about the topic title and what if I want to use [ c o d e ] and [ / c o d e] tags because I'm posting non VB code?....
    Well if you are going to offend me at least spell my name right Anyhow I mentioned the topic title because if you had read Acidic's sticky you would see that he is requesting that people do that and it's my job as a moderator to remind people of those things.

    I don't understand what you mean about using [code][/code] tags.

  29. #29
    Frenzied Member Magiaus's Avatar
    Join Date
    Mar 2002
    Location
    swamp land
    Posts
    1,267

    Thumbs up

    I always think that when I read your signiture and I was trying to rib you, but I failed
    Magiaus

    If I helped give me some points.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width