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
(#16)
Old
Pragma's Avatar
Pragma is Offline
Contributor
Rep Power: 3
Reputation: 257
Pragma is a jewel in the roughPragma is a jewel in the roughPragma is a jewel in the rough
 
Posts: 588
Join Date: Feb 2007
Location: main(String[] args)
03-17-2008

i believe he meant to put int main()
its just a typo



Reply With Quote

Donate to remove ads.
(#17)
Old
Apoc's Avatar
Apoc is Offline
c|_| My care cup is empty
Legendary User
Rep Power: 5
Reputation: 688
Apoc is a splendid one to beholdApoc is a splendid one to beholdApoc is a splendid one to beholdApoc is a splendid one to beholdApoc is a splendid one to beholdApoc is a splendid one to behold
 
Posts: 734
Join Date: Jan 2008
03-18-2008

Using a "return;" in a void function is how you jump out of the current function without executing any code below that point. "return;" and "return something;" are completely different.

It's bad to add returns to void functions unless you want to explicitly exit out of the current function. (Say you hit an error, and don't want to execute any further code in the method)


VB skills is an oxymoron. - Cypher
Reply With Quote
(#18)
Old
Glitchy's Avatar
Glitchy is Offline
Moderator

Rep Power: 8
Reputation: 1025
Glitchy has much to be proud ofGlitchy has much to be proud ofGlitchy has much to be proud ofGlitchy has much to be proud ofGlitchy has much to be proud ofGlitchy has much to be proud ofGlitchy has much to be proud ofGlitchy has much to be proud of
 
Posts: 813
Join Date: Jun 2007
Location: DE... Where in DE...
03-18-2008

If you think 4 line of code is bad for a hello world you should try ASM

Here is a "hello world" app for a ti-83 calculator. I use to make games in this language, and I'm having to pick ASM back up for some PIC programming I'm doing.

Code:
.NOLIST
#define   EQU   .equ
#define   equ   .equ
#define   END   .end
#define   end   .end
#include "ti83plus.inc"
.LIST

     .org 9D93h
     .db ,$6D
      ld a,0
      ld (CURCOL),a
      ld (CURROW),a
      ld hl,text
      B_CALL(_PutS)
      ret
text:
      .db "Hello, World",0

.end
end


[Only registered and activated users can see links. ]
[Only registered and activated users can see links. ]

Last edited by Glitchy; 03-18-2008 at 04:52 AM..
Reply With Quote
(#19)
Old
Apoc's Avatar
Apoc is Offline
c|_| My care cup is empty
Legendary User
Rep Power: 5
Reputation: 688
Apoc is a splendid one to beholdApoc is a splendid one to beholdApoc is a splendid one to beholdApoc is a splendid one to beholdApoc is a splendid one to beholdApoc is a splendid one to behold
 
Posts: 734
Join Date: Jan 2008
03-18-2008

Hence why nobody codes entirely in ASM. :P

You'd commit suicide before you got anywhere with ASM.


VB skills is an oxymoron. - Cypher
Reply With Quote
(#20)
Old
fattony is Offline
Site n00b.. (A leecher if I've been here for more than a month and can't earn 5 rep)
Rep Power: 2
Reputation: 1
fattony is an unknown quantity at this point
 
Posts: 11
Join Date: Dec 2006
03-18-2008

Code:
++++++++++[>+++++++>++++++++++>+++<<<-]>++.>+.+++++++
..+++.>++.<<+++++++++++++++.>.+++.------.--------.>+.
See, only two lines! Brain**** ftw
Reply With Quote
(#21)
Old
Glitchy's Avatar
Glitchy is Offline
Moderator

Rep Power: 8
Reputation: 1025
Glitchy has much to be proud ofGlitchy has much to be proud ofGlitchy has much to be proud ofGlitchy has much to be proud ofGlitchy has much to be proud ofGlitchy has much to be proud ofGlitchy has much to be proud ofGlitchy has much to be proud of
 
Posts: 813
Join Date: Jun 2007
Location: DE... Where in DE...
03-18-2008

Quote:
Originally Posted by Apoc View Post
Hence why nobody codes entirely in ASM. :P

You'd commit suicide before you got anywhere with ASM.

True a lot of PIC's not a days can wrap the asm code in C++


[Only registered and activated users can see links. ]
[Only registered and activated users can see links. ]
Reply With Quote
(#22)
Old
Nebzor is Offline
Site n00b.. (A leecher if I've been here for more than a month and can't earn 5 rep)
Rep Power: 0
Reputation: 1
Nebzor is an unknown quantity at this point
 
Posts: 3
Join Date: Apr 2008
04-06-2008

Just to add my purist taint, it should be as follows, and only as follows;

Code:
#include <iostream>

int main(){
         std::cout << "Hello World!" << std::endl;
         return 0;
}
Reply With Quote
(#23)
Old
Cypher's Avatar
Cypher is Offline
IDA Jedi
Legendary User
Rep Power: 9
Reputation: 832
Cypher is a splendid one to beholdCypher is a splendid one to beholdCypher is a splendid one to beholdCypher is a splendid one to beholdCypher is a splendid one to beholdCypher is a splendid one to beholdCypher is a splendid one to behold
 
Posts: 2,378
Join Date: Apr 2006
Location: WoW.exe
04-07-2008

Quote:
Originally Posted by Apoc View Post
Hence why nobody codes entirely in ASM. :P

You'd commit suicide before you got anywhere with ASM.

I use ASM. ^_^

Not to write entire programs in but inline in the DLLs I inject into WoW.


"Dream as if you'll live forever, live as if you'll die today." - James Dean
Reply With Quote
(#24)
Old
Viter's Avatar
Viter is Online
Member of The Month
Rep Power: 4
Reputation: 387
Viter is just really niceViter is just really niceViter is just really niceViter is just really nice
 
Posts: 1,701
Join Date: Aug 2007
Location: Denmark
04-12-2008

or you could write:

Code:
include <iostream>
using namespace std;

int main()
{
cout <<"Hello World"<<endl;
system("pause")
}





Last edited by Viter; 04-12-2008 at 02:09 PM..
Reply With Quote
(#25)
Old
Archdruid's Avatar
Archdruid is Offline
Site n00b.. (A leecher if I've been here for more than a month and can't earn 5 rep)
Rep Power: 1
Reputation: 1
Archdruid is an unknown quantity at this point
 
Posts: 8
Join Date: Apr 2008
04-26-2008

What compilers are you guys using?
Reply With Quote
(#26)
Old
Sacred91 is Offline
Site n00b.. (A leecher if I've been here for more than a month and can't earn 5 rep)
Rep Power: 0
Reputation: 1
Sacred91 is an unknown quantity at this point
 
Posts: 1
Join Date: Jun 2008
06-16-2008

I'm using Microsoft visual c++ 2008 oder Code::Blocks
Reply With Quote
(#27)
Old
kruz2 is Offline
Site n00b.. (A leecher if I've been here for more than a month and can't earn 5 rep)
Rep Power: 1
Reputation: 2
kruz2 is an unknown quantity at this point
 
Posts: 31
Join Date: Mar 2008
06-19-2008

sorry,
Deleted.
Reply With Quote
(#28)
Old
Recarver is Offline
Site n00b.. (A leecher if I've been here for more than a month and can't earn 5 rep)
Rep Power: 0
Reputation: 1
Recarver is an unknown quantity at this point
 
Posts: 2
Join Date: Aug 2008
08-25-2008

C:
Quote:
#include <stdio.h>

#include <iostream> // Incializing for windows

int main(void)
{
printf("Hello World!");

// Incializing for windows
system("pause");

return 0;
}
C++:
Quote:
#include <iostream>

using namespace std;

int main()
{

cout <<"Hello World!";

// Incializing for windows
cin.get();
cin.get();

return 0;
}
good luck
Reply With Quote
(#29)
Old
unknown405 is Offline
Site n00b.. (A leecher if I've been here for more than a month and can't earn 5 rep)
Rep Power: 1
Reputation: 1
unknown405 is an unknown quantity at this point
 
Posts: 8
Join Date: Aug 2008
08-26-2008

Oh my god, this is obviously a thread for new coders trying to learn - PLEASE don't get them in the habit of using System("anything"). It's fine for HW assignments or meaningless little programs (like Hello World) but if you get them in the habit of using it, then they'll use it in their finished projects in the future. It's slow and it's a security risk, among other things it also tags you as a complete beginner. So to summarize, DONT USE SYSTEM("anything")!!

I've put together an upgrade to Hello World that contains a good alternative to using system("pause") as well as posting a version where every line is commented because I know this is generally for beginners and another code snippet with no comments so the more advanced users still using system("pause") can read it more legibly. One more thing I would like to add is that yes, there are a lot of alternatives to system("pause") but remember that a lot more methods than system("pause") have some kind of flaw in them.

Code:
//HelloUser

//Include necessary preprocessors
#include <iostream> //Used for input/output (cin/cout)
#include <string> //Used for string
#include <limits> //Used for the numeric_limits

//This prevents us from having to do "std::" before everything
using namespace std;

//Start of function
int main ()
{
//String declaration for our input
string str;

//Outputs on the screen, "What is your name?"
  cout << "What is your name? ";
//Here we take your answer to the question and convert it to our string declaration
	cin >> str;
//Outputs Hello%s, my name is Hello%s (with %s being input stream) then skips/ends line
  cout << "Hello " << str << ", my name is Hello" << str << endl;

//Alternative to system("pause") which should NEVER BE USED!!
	//This will ensure that the original ENTER was pushed after the final <<
  cin.ignore( numeric_limits<streamsize>::max(), 'n' );

//Outputs on screen you can quit by pressing ENTER
  cout << "Press ENTER to quit!";

//Alternative to system("pause") which should NEVER BE USED!!
  cin.ignore(numeric_limits<streamsize>::max(), 'n' );

//Outputs the text below
  cout << "Bye, make sure you program me even better next time!!";

//Return function telling our program that it exited with no errors
  return 0;
}
Code:
//HelloUser

#include <iostream> 
#include <string>
#include <limits>

using namespace std;

int main ()
{
string str;
  cout << "What is your name? ";
cin >> str;
  cout << "Hello " << str << ", my name is Hello" << str << endl;

cin.ignore( numeric_limits<streamsize>::max(), 'n' );
  cout << "Press ENTER to quit!";
cin.ignore(numeric_limits<streamsize>::max(), 'n' );
  cout << "Bye, make sure you program me even better next time!!";

  return 0;
}
PS: I also just noticed that you had said for C++ to use cin.get() twice. That's, again, a completely improper way of going about it and doesn't even make sense. Your making the user have to press enter TWICE while giving him absolutely no notification of what he's supposed to do. Please learn to do it the right way now before you get in a bad habit of that.

Last edited by unknown405; 08-26-2008 at 02:30 PM..
Reply With Quote
(#30)
Old
breezy22 is Offline
Site n00b.. (A leecher if I've been here for more than a month and can't earn 5 rep)
Rep Power: 1
Reputation: 1
breezy22 is an unknown quantity at this point
 
Posts: 14
Join Date: Jul 2008
08-27-2008

Quote:
Originally Posted by unknown405 View Post
Oh my god, this is obviously a thread for new coders trying to learn - PLEASE don't get them in the habit of using System("anything"). It's fine for HW assignments or meaningless little programs (like Hello World) but if you get them in the habit of using it, then they'll use it in their finished projects in the future. It's slow and it's a security risk, among other things it also tags you as a complete beginner. So to summarize, DONT USE SYSTEM("anything")!!

I've put together an upgrade to Hello World that contains a good alternative to using system("pause") as well as posting a version where every line is commented because I know this is generally for beginners and another code snippet with no comments so the more advanced users still using system("pause") can read it more legibly. One more thing I would like to add is that yes, there are a lot of alternatives to system("pause") but remember that a lot more methods than system("pause") have some kind of flaw in them.

Code:
//HelloUser

//Include necessary preprocessors
#include <iostream> //Used for input/output (cin/cout)
#include <string> //Used for string
#include <limits> //Used for the numeric_limits

//This prevents us from having to do "std::" before everything
using namespace std;

//Start of function
int main ()
{
//String declaration for our input
string str;

//Outputs on the screen, "What is your name?"
  cout << "What is your name? ";
//Here we take your answer to the question and convert it to our string declaration
	cin >> str;
//Outputs Hello%s, my name is Hello%s (with %s being input stream) then skips/ends line
  cout << "Hello " << str << ", my name is Hello" << str << endl;

//Alternative to system("pause") which should NEVER BE USED!!
	//This will ensure that the original ENTER was pushed after the final <<
  cin.ignore( numeric_limits<streamsize>::max(), 'n' );

//Outputs on screen you can quit by pressing ENTER
  cout << "Press ENTER to quit!";

//Alternative to system("pause") which should NEVER BE USED!!
  cin.ignore(numeric_limits<streamsize>::max(), 'n' );

//Outputs the text below
  cout << "Bye, make sure you program me even better next time!!";

//Return function telling our program that it exited with no errors
  return 0;
}
Code:
//HelloUser

#include <iostream> 
#include <string>
#include <limits>

using namespace std;

int main ()
{
string str;
  cout << "What is your name? ";
cin >> str;
  cout << "Hello " << str << ", my name is Hello" << str << endl;

cin.ignore( numeric_limits<streamsize>::max(), 'n' );
  cout << "Press ENTER to quit!";
cin.ignore(numeric_limits<streamsize>::max(), 'n' );
  cout << "Bye, make sure you program me even better next time!!";

  return 0;
}
PS: I also just noticed that you had said for C++ to use cin.get() twice. That's, again, a completely improper way of going about it and doesn't even make sense. Your making the user have to press enter TWICE while giving him absolutely no notification of what he's supposed to do. Please learn to do it the right way now before you get in a bad habit of that.
Yea I agree the cin.get() makes no sense. I would just return 0 and let it print the line. It's a hello world program the point is simple to print "Hello World".
Reply With Quote
Reply

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.4
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.2.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 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336