MMOwned - World of Warcraft Exploits, Hacks, Bots and Guides

Homepage Register FAQ Members Mark Forums Read Advertise Marketplace FPSowned


Go Back   MMOwned - World of Warcraft Exploits, Hacks, Bots and Guides > Programming > Programming section > C and C++
Reload this Page Hello World, in C++.
C and C++ Discussions about C and C++

Reply
 
LinkBack Thread Tools
Hello World, in C++.
(#1)
Old
MaiN is Offline
Contributor
Rep Power: 2
Reputation: 110
MaiN will become famous soon enoughMaiN will become famous soon enough
 
Posts: 356
Join Date: Sep 2006
Hello World, in C++. - 03-14-2008

Like all the others, here we go!

Code:
#include <iostream>

int main()
{
std::cout << "Hello worldn";
return 0;
}
The first line, "#include <iostream>" includes the library iostream, which is used later, for the command "std::cout". If we removed it, we would get that "std" isn't an class or namespace, and that "cout" has an undeclared identifier (std).

The next line, "int main()" creates the main function, this function is needed in EVERY C++ program.

Next line, "{" shows where the main() function start.

Next line, "std::cout << "Hello world!\n";
"std" is the identifier for "cout", without "std::" infront of it, we would get a nasty error. We could actually have added "using namespace std;" after "#include <iostream>", and we wouldn't have to use "std::" anywhere in our program. "cout" is used to show something on the screen. "<<" Those two are needed before we show something on the screen, and the next i'm sure you can guess what does. The "\n" part specifies a line-break. Instead of "\n", we could've used "std::cout << "Hello world!" std::endl;" which makes it end the line (endl = end line).
The next line, "}" closes the main() function.
That was the legendary Hello World program in C++.


I was here. ~Dragon[Sky] I was here too. ~Kuiren

Last edited by MaiN; 03-21-2008 at 06:15 PM.
Reply With Quote

Donate to remove ads.
(#2)
Old
ReidE96's Avatar
ReidE96 is Offline
Contributor
Rep Power: 3
Reputation: 237
ReidE96 has a spectacular aura aboutReidE96 has a spectacular aura aboutReidE96 has a spectacular aura about
 
Posts: 617
Join Date: Dec 2006
Location: Scotland
03-14-2008

All that just for hello world? o.0

Yeah, this is one of the reasons I don't like C++. Same amount of code in DB gives a spinning cube, and hello world needs 2 lines.


Reply With Quote
(#3)
Old
Marlo's Avatar
Marlo is Offline
Biggest Wall-e fan EVAAAA
Legendary User
Rep Power: 8
Reputation: 671
Marlo is a splendid one to beholdMarlo is a splendid one to beholdMarlo is a splendid one to beholdMarlo is a splendid one to beholdMarlo is a splendid one to beholdMarlo is a splendid one to behold
 
Posts: 2,572
Join Date: Jul 2006
Location: 127.0.0.1
03-14-2008

Quote:
Originally Posted by ReidE96 View Post
All that just for hello world? o.0

Yeah, this is one of the reasons I don't like C++. Same amount of code in DB gives a spinning cube, and hello world needs 2 lines.
but then again who the **** needs a spinning cube?


Reply With Quote
(#4)
Old
RyudoP is Offline
Master Sergeant
Rep Power: 0
Reputation: 58
RyudoP will become famous soon enough
 
Posts: 88
Join Date: Nov 2007
03-14-2008

Think it'd be good to add a return 0; at the end aswell. Most compilers will work fine without it (they just assume the program ends after there aren't any more statements), but others require it.
Reply With Quote
(#5)
Old
Functions is Offline
Master Sergeant
Rep Power: 1
Reputation: 11
Functions is on a distinguished road
 
Posts: 129
Join Date: Dec 2007
03-14-2008

Lololol.... This is an LOL moment LOL MOMENTS!!!!
Reply With Quote
(#6)
Old
insanesk8123's Avatar
insanesk8123 is Offline
Contributor
Rep Power: 3
Reputation: 236
insanesk8123 has a spectacular aura aboutinsanesk8123 has a spectacular aura aboutinsanesk8123 has a spectacular aura about
 
Posts: 572
Join Date: Feb 2007
Location: main(String[] args)
03-14-2008

Quote:
Yeah, this is one of the reasons I don't like C++. Same amount of code in DB gives a spinning cube, and hello world needs 2 lines.
the reason why C++ is so leet is because how accurate it is, if you can make a spinning 3d cube with four lines of code there proly isnt too much variety in that language.


By Jerbab
Reply With Quote
(#7)
Old
**Sweeny**'s Avatar
**Sweeny** is Offline
Knight-Lieutenant
Rep Power: 1
Reputation: 32
**Sweeny** is on a distinguished road
 
Posts: 282
Join Date: Dec 2007
03-15-2008

If this is for begginers you shouldn't confuse them by shortening the c++ script down you should keep it like
#include <iostream>

using namespace std;

int main()
{
cout<<"Hello World!\n";
cin.get();
}





Reply With Quote
(#8)
Old
MaiN is Offline
Contributor
Rep Power: 2
Reputation: 110
MaiN will become famous soon enoughMaiN will become famous soon enough
 
Posts: 356
Join Date: Sep 2006
03-15-2008

Uhmm, your's just as long as mine..
And Reid, you ****ing have to enter a full-screen game-type mode, to even program DarkCode.... Which sucks, kinda.
And WTF, just because you can make a spinning cube in 4 lines, doesn't mean it's that good, what about making a language which can make spinning cubes like this:
"CREATE CUBE -> SPIN"
So, if i create a language which could do that it would be the best language in the world?


I was here. ~Dragon[Sky] I was here too. ~Kuiren

Last edited by MaiN; 03-15-2008 at 01:29 PM.
Reply With Quote
(#9)
Old
**Sweeny**'s Avatar
**Sweeny** is Offline
Knight-Lieutenant
Rep Power: 1
Reputation: 32
**Sweeny** is on a distinguished road
 
Posts: 282
Join Date: Dec 2007
03-15-2008

Quote:
And Reid, you ****ing have to enter a full-screen game-type mode, to even program DarkCode.... Which sucks, kinda.
And WTF, just because you can make a spinning cube in 4 lines, doesn't mean it's that good, what about making a language which can make spinning cubes like this:
"CREATE CUBE -> SPIN"
So, if i create a language which could do that it would be the best language in the world?
HAHAAAA NICE!!! pwned reid


Reply With Quote
(#10)
Old
-Lex is Offline
Banned
Rep Power: 0
Reputation: 1056
-Lex has much to be proud of-Lex has much to be proud of-Lex has much to be proud of-Lex has much to be proud of-Lex has much to be proud of-Lex has much to be proud of-Lex has much to be proud of-Lex has much to be proud of
 
Posts: 960
Join Date: Jun 2007
Location: Hyboria
03-16-2008

Quote:
msgbox (0, "Hello", "World")
Autoit ftw
Reply With Quote
(#11)
Old
EcHoEs's Avatar
EcHoEs is Online
Contributor
Rep Power: 3
Reputation: 205
EcHoEs has a spectacular aura aboutEcHoEs has a spectacular aura aboutEcHoEs has a spectacular aura about
 
Posts: 1,069
Join Date: Sep 2006
Location: in ur cmputer
03-16-2008

Then again who would want app to say "Hello world"



Reply With Quote
(#12)
Old
ReidE96's Avatar
ReidE96 is Offline
Contributor
Rep Power: 3
Reputation: 237
ReidE96 has a spectacular aura aboutReidE96 has a spectacular aura aboutReidE96 has a spectacular aura about
 
Posts: 617
Join Date: Dec 2006
Location: Scotland
03-16-2008

EcHoEs makes a good point.

And MaiN, if that was all your language could do I'd be worried.

insanesk - No, you can be really specific with it. You just use some other commands.


Reply With Quote
(#13)
Old
Apoc's Avatar
Apoc is Offline
c|_| My care cup is empty
Rep Power: 4
Reputation: 468
Apoc is a glorious beacon of lightApoc is a glorious beacon of lightApoc is a glorious beacon of lightApoc is a glorious beacon of lightApoc is a glorious beacon of light
 
Posts: 562
Join Date: Jan 2008
03-16-2008

You're all missing the point of what C++ and this program is about.

"Hello World" is the traditional first program you do in any language.

DarkBasic is more of an easy way to do not so complex VISUAL programming.

C++ is a language where there are no limits as to what you can do. Literally.

The fact that C++ allows you to manually control the memory your application uses is already a main point why this language has a small heads up over some other languages. Not to mention 90% of the games you play are not made in DarkBasic, but a combination of C++ and C. (Yes sometimes you need some managed code which is easier to do in C than C++)

Now, with my ranting out of the way, please stay on topic. No need to bash a language because it takes 4 lines to write a hello world app.

Ryudop, if you're still using a compiler that requires the 0, you should seriously look into getting a new compiler. The last time I used a compiler that required that was back in 97.


Reply With Quote
(#14)
Old
RyudoP is Offline
Master Sergeant
Rep Power: 0
Reputation: 58
RyudoP will become famous soon enough
 
Posts: 88
Join Date: Nov 2007
03-16-2008

Quote:
Originally Posted by Apoc View Post
Ryudop, if you're still using a compiler that requires the 0, you should seriously look into getting a new compiler. The last time I used a compiler that required that was back in 97.
Yeah i know it isn't really needed, but it's a good habit to always include a return statement in non-void functions. (or even in void functions)


*edit*
@post below, void indicates that no value is returned, but you still return to the function that called you.. so just 'return;'.

Last edited by RyudoP; 03-16-2008 at 07:41 PM.
Reply With Quote
(#15)
Old
Apoc's Avatar
Apoc is Offline
c|_| My care cup is empty
Rep Power: 4
Reputation: 468
Apoc is a glorious beacon of lightApoc is a glorious beacon of lightApoc is a glorious beacon of lightApoc is a glorious beacon of lightApoc is a glorious beacon of light
 
Posts: 562
Join Date: Jan 2008
03-16-2008

Why would you add a return statement in a void function? The sole purpose of a void is to NOT return anything. Most compilers would throw an error about adding a return in a void function...


Reply With Quote
Reply

Donate to remove ads.

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are Off
Refbacks are On




Powered by vBulletin® Version 3.7.2
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
LinkBacks Enabled by vBSEO 3.1.0
vBulletin Skin developed by: vBStyles.com


1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320