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 |
|
|
|
| 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
|
  |
| 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 |
|
|
|
| 15 Jan 2012 07:49 PM |
Oh.
So if it returned a string, it would be string main()? |
|
|
| Report Abuse |
|
|
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
|
  |
| 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
|
  |
| 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
|
  |
| Joined: 03 Aug 2008 |
| Total Posts: 22071 |
|
|
| 15 Jan 2012 07:51 PM |
| I started learning today, around 10 minutes ago |
|
|
| Report Abuse |
|
|
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
|
  |
| 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 |
|
|
|
| 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
|
  |
| 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 |
|
|
|
| 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 |
|
|
|
| 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 |
|
|
|
| 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 |
|
|
|
| 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
|
  |
| Joined: 23 May 2009 |
| Total Posts: 7534 |
|
|
| 16 Jan 2012 02:25 PM |
It's also platform dependent.
---------- ~ pwnedu46, the unicorn ~ |
|
|
| Report Abuse |
|
|