Click to See Complete Forum and Search --> : How do I make this more efficient?
Kasracer
Dec 17th, 2003, 02:58 PM
#include <iostream>
int main()
{
std::cout << "Hello World!" << std::endl;
}
mendhak
Dec 17th, 2003, 03:11 PM
#include <iostream>
int main()
{
cout << "Hello World!";
}
:confused:
???
Acidic
Dec 17th, 2003, 03:12 PM
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::
Kasracer
Dec 17th, 2003, 03:15 PM
Originally posted by mendhak
#include <iostream>
int main()
{
cout << "Hello World!";
}
:confused:
??? That isn't more efficient :mad:
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.
spoiledkid
Dec 17th, 2003, 03:16 PM
I do not think you need to type that, it should work without that thing. std stands for standard output .....
Kasracer
Dec 17th, 2003, 03:23 PM
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
visualAd
Dec 17th, 2003, 03:32 PM
Originally posted by kasracer
#include <iostream>
int main()
{
std::cout << "Hello World!" << std::endl;
}
Write it in C :D
#include <stdio.h>
int main(void)
{
puts ("Hello World");
return 0;
}
CornedBee
Dec 17th, 2003, 05:05 PM
Why would you want it more efficient?
If you really want, you can write it directly to the buffer, but...
Memnoch1207
Dec 17th, 2003, 05:15 PM
here you go :D
More efficient AND managed code!
using System;
class Class1
{
public static void Main()
{
Console.WriteLine("HELLO WORLD");
}
}
kovan
Dec 17th, 2003, 05:33 PM
USE NAME SPACE STD DAMN MEnDHAK :)
#include <iostream>
using namespace std;
int main()
{
cout << "Hello World!" << endl;
}
CornedBee
Dec 17th, 2003, 05:37 PM
Managed code is never more efficient.
C# might be shorter, but this code isn't.
VBD
Dec 17th, 2003, 06:07 PM
Sorry, I don't know asm :bigyello:
Kasracer
Dec 17th, 2003, 06:30 PM
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 :D
More efficient AND managed code!
using System;
class Class1
{
public static void Main()
{
Console.WriteLine("HELLO WORLD");
}
}
Eww hell naws. Mine will atleast compile on linux :D
alkatran
Dec 17th, 2003, 09:57 PM
QBasic:
Print "HELLO WORLD!"
It doesn't get much shorter than that.
plenderj
Dec 18th, 2003, 03:23 AM
Originally posted by kasracer
Mine will atleast compile on linux :D
mono ;)
CornedBee
Dec 18th, 2003, 04:53 AM
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.
visualAd
Dec 18th, 2003, 06:18 AM
Originally posted by alkatran
QBasic:
Print "HELLO WORLD!"
It doesn't get much shorter than that.
That would make it less efficient though.
Osiris
Dec 18th, 2003, 09:59 PM
I'll give it a try...
#include<iostream.h>
int main()
{
cout << "Hello World!\n";
return 0;
}
i think this would be the code for assembly.
.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
CornedBee
Dec 19th, 2003, 09:02 AM
DOS assembly...
MartinLiss
Dec 20th, 2003, 05:08 PM
Please include the language in all subject lines in this forum.
dis1411
Dec 25th, 2003, 01:31 AM
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..
CornedBee
Dec 25th, 2003, 05:47 AM
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.
dis1411
Dec 25th, 2003, 10:02 PM
Originally posted by CornedBee
And feeding ASCII values makes no difference.
y is this? are they converted when compiling the prog?
Kasracer
Dec 25th, 2003, 10:13 PM
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.....
dis1411
Dec 26th, 2003, 03:26 PM
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
CornedBee
Dec 26th, 2003, 06:00 PM
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.
Magiaus
Mar 3rd, 2004, 03:21 PM
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..
MartinLiss
Mar 3rd, 2004, 04:08 PM
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 tags.
Magiaus
Mar 3rd, 2004, 07:23 PM
I always think that when I read your signiture and I was trying to rib you, but I failed :cool:
vbforums.com
Copyright Internet.com Inc., All Rights Reserved.