|
-
Dec 17th, 2003, 02:58 PM
#1
How do I make this more efficient?
Code:
#include <iostream>
int main()
{
std::cout << "Hello World!" << std::endl;
}
-
Dec 17th, 2003, 03:11 PM
#2
Code:
#include <iostream>
int main()
{
cout << "Hello World!";
}

???
-
Dec 17th, 2003, 03:12 PM
#3
Frenzied Member
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. 
-
Dec 17th, 2003, 03:15 PM
#4
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.
-
Dec 17th, 2003, 03:16 PM
#5
Hyperactive Member
I do not think you need to type that, it should work without that thing. std stands for standard output .....
-
Dec 17th, 2003, 03:23 PM
#6
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
-
Dec 17th, 2003, 03:32 PM
#7
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;
}
-
Dec 17th, 2003, 05:05 PM
#8
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.
-
Dec 17th, 2003, 05:15 PM
#9
Frenzied Member
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
-
Dec 17th, 2003, 05:33 PM
#10
Frenzied Member
USE NAME SPACE STD DAMN MEnDHAK 
Code:
#include <iostream>
using namespace std;
int main()
{
cout << "Hello World!" << endl;
}
-
Dec 17th, 2003, 05:37 PM
#11
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.
-
Dec 17th, 2003, 06:07 PM
#12
Hyperactive Member
Write it ASM
Sorry, I don't know asm
-
Dec 17th, 2003, 06:30 PM
#13
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
-
Dec 17th, 2003, 09:57 PM
#14
Fanatic Member
QBasic:
It doesn't get much shorter than that.
Don't pay attention to this signature, it's contradictory.
-
Dec 18th, 2003, 03:23 AM
#15
Retired VBF Adm1nistrator
Originally posted by kasracer
Mine will atleast compile on linux
mono
Microsoft MVP : Visual Developer - Visual Basic [2004-2005]
-
Dec 18th, 2003, 04:53 AM
#16
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.
-
Dec 18th, 2003, 06:18 AM
#17
Originally posted by alkatran
QBasic:
It doesn't get much shorter than that.
That would make it less efficient though.
-
Dec 18th, 2003, 09:59 PM
#18
Addicted Member
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
-
Dec 19th, 2003, 09:02 AM
#19
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.
-
Dec 20th, 2003, 05:08 PM
#20
Please include the language in all subject lines in this forum.
-
Dec 25th, 2003, 01:31 AM
#21
Frenzied Member
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..
-
Dec 25th, 2003, 05:47 AM
#22
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.
-
Dec 25th, 2003, 10:02 PM
#23
Frenzied Member
Originally posted by CornedBee
And feeding ASCII values makes no difference.
y is this? are they converted when compiling the prog?
-
Dec 25th, 2003, 10:13 PM
#24
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.....
-
Dec 26th, 2003, 03:26 PM
#25
Frenzied Member
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.
-
Dec 26th, 2003, 06:00 PM
#26
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.
-
Mar 3rd, 2004, 03:21 PM
#27
Frenzied Member
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.
-
Mar 3rd, 2004, 04:08 PM
#28
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.
-
Mar 3rd, 2004, 07:23 PM
#29
Frenzied Member
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
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|