generic image
Processing...
  • Games
  • Catalog
  • Develop
  • Robux
  • Search in Players
  • Search in Games
  • Search in Catalog
  • Search in Groups
  • Search in Library
  • Log In
  • Sign Up
  • Games
  • Catalog
  • Develop
  • Robux
   
ROBLOX Forum » Game Creation and Development » Scripters
Home Search
 

Re: My first (and simple) C++ code

Previous Thread :: Next Thread 
mew903 is not online. mew903
Joined: 03 Aug 2008
Total Posts: 22071
15 Jan 2012 07:42 PM
It's .... so .... simple :\


#include >iostream< -- HTML thing blocked it
#include >string<

int main()
{
string pause;
cout << "Hello world!";
cin >> pause;
return 0;
}
Report Abuse
Techboy6601 is not online. Techboy6601
Joined: 29 Jun 2009
Total Posts: 4914
15 Jan 2012 07:44 PM
I don't even know what this is...


And anyways, why is the main function an INTEGER!?

C++, Y U SO CONFUSING
Report Abuse
myrkos is not online. myrkos
Joined: 06 Sep 2010
Total Posts: 8072
15 Jan 2012 07:47 PM
@^, it says it returns an integer, it isn't itself an integer.
Report Abuse
Techboy6601 is not online. Techboy6601
Joined: 29 Jun 2009
Total Posts: 4914
15 Jan 2012 07:49 PM
Oh.

So if it returned a string, it would be string main()?
Report Abuse
LocalChum is not online. LocalChum
Joined: 04 Mar 2011
Total Posts: 6906
15 Jan 2012 07:50 PM
I expect you to know the full Win32 API in one week, okay?
Report Abuse
jode6543 is not online. jode6543
Joined: 16 Jun 2009
Total Posts: 5363
15 Jan 2012 07:50 PM
Adding to what Myrkos said, the integer it returns is the program exit code.

"Be nice to nerds. Chances are you'll end up working for one. -Bill Gates"
Report Abuse
myrkos is not online. myrkos
Joined: 06 Sep 2010
Total Posts: 8072
15 Jan 2012 07:50 PM
Well yes, if you're using the string from the standard library.

But main can only return integers, as a status code to the OS.
Report Abuse
mew903 is not online. mew903
Joined: 03 Aug 2008
Total Posts: 22071
15 Jan 2012 07:51 PM
I started learning today, around 10 minutes ago
Report Abuse
1Ra is not online. 1Ra
Joined: 02 May 2010
Total Posts: 2400
15 Jan 2012 07:52 PM
you might want to add
system("pause");
at the end.
Report Abuse
LocalChum is not online. LocalChum
Joined: 04 Mar 2011
Total Posts: 6906
15 Jan 2012 07:57 PM
@1ra

System calls are evil.

Either use cin.get(), or _getch() (include conio.h).
Report Abuse
pokelover980 is not online. pokelover980
Joined: 12 Jun 2009
Total Posts: 4141
15 Jan 2012 08:17 PM
Your code wouldn't compile, as a note. You either have to add "using namespace std;" before your main function, or you be more clean/efficient and prefix anything in the standard namespace with std:: (cin would become std::cin, string would become std::string, and cout would become std::cout in your code).
Report Abuse
pighead10 is not online. pighead10
Joined: 03 May 2009
Total Posts: 10341
16 Jan 2012 09:01 AM
"I expect you to know the full windows API within a week"

I still haven't attempted to learn that.
Report Abuse
pokelover980 is not online. pokelover980
Joined: 12 Jun 2009
Total Posts: 4141
16 Jan 2012 12:03 PM
"I still haven't attempted to learn that."

And you never should, you should just use the nice third party libraries out there that do it for you. Or, if you're just staying on Windows, go to C# since it gives access to the Windows API in a nice simple way.
Report Abuse
NecroBumpist is not online. NecroBumpist
Joined: 12 Sep 2010
Total Posts: 4198
16 Jan 2012 12:06 PM
>`system("pause");`

inb4 stravant explains why this is bad and you should feel bad for using it again
Report Abuse
pokelover980 is not online. pokelover980
Joined: 12 Jun 2009
Total Posts: 4141
16 Jan 2012 12:16 PM
"inb4 stravant explains why this is bad and you should feel bad for using it again"

inb4 stravant ninja's me while I try and explain

Any call to "system" is bad because it is. It's not portable to every system, only those with a "PAUSE" command at the system level. It's also incredibly inefficient, as it works like this: 1. Suspend your program. 2. Call the operating system. 3. Open a new operating system shell in a sub process (essentially relaunching the OS in another process). 4. The OS finds the command you passed to "system". 5. Allocate memory to execute command. 6. Execute command, and do whatever it needs to, such as wait for a keystroke for "PAUSE". 7. Deallocate memory. 8. Exit the OS subprocess. 9. Return to your program.
Report Abuse
NecroBumpist is not online. NecroBumpist
Joined: 12 Sep 2010
Total Posts: 4198
16 Jan 2012 12:32 PM
inb4 I copypasta stravant's original post:

system("pause") is bad to use.
Why? Here's what happens when you make a call to system("pause").
-The process forks and entirely new process.
-The new process loads up a system shell
-The process pipes the new process' output to the current output
-The process pipes the command which you passed to "system" into the shell process
-The process does a join to wait for the command to finish
-The shell fires up it's interpreter to parse and run the command you entered
-The shell process then does a call to the same OS function as cin.get() does
-The shell waits for input from that function
-The shell gets it, and ends the process
-Your process now gets fired up again, and reads the return status from the closed process
-Which it then returns to you.
It's a hugely roundabout way to do what you want. It requires not only the parsing and interpretation of the string you pass in, but the creation of a whole new process to run it in.

From: http://www.roblox.com/Forum/ShowPost.aspx?PostID=52293633


Report Abuse
pwnedu46 is not online. pwnedu46
Joined: 23 May 2009
Total Posts: 7534
16 Jan 2012 02:25 PM
It's also platform dependent.


----------
    ~ pwnedu46, the unicorn ~
Report Abuse
Previous Thread :: Next Thread 
Page 1 of 1
 
 
ROBLOX Forum » Game Creation and Development » Scripters
   
 
   
  • About Us
  • Jobs
  • Blog
  • Parents
  • Help
  • Terms
  • Privacy

©2017 Roblox Corporation. Roblox, the Roblox logo, Robux, Bloxy, and Powering Imagination are among our registered and unregistered trademarks in the U.S. and other countries.



Progress
Starting Roblox...
Connecting to Players...
R R

Roblox is now loading. Get ready to play!

R R

You're moments away from getting into the game!

Click here for help

Check Remember my choice and click Launch Application in the dialog box above to join games faster in the future!

Gameplay sponsored by:
Loading 0% - Starting game...
Get more with Builders Club! Join Builders Club
Choose Your Avatar
I have an account
generic image