| View previous topic :: View next topic |
| Author |
Message |
patsmokeswii Grandmaster Cheater Supreme
Reputation: 0
Joined: 26 Aug 2007 Posts: 1039 Location: Perth Amboy, NJ
|
Posted: Tue Jan 22, 2008 10:21 am Post subject: [Request] Help on C++ |
|
|
Well, I am trying to begin programing, and learning how to do stuff, so I am wondering, why is it I get an error with "Hello World" in Microsoft visual studio '08.
This is what I write:
| Code: |
#include <iostream>
using namespace std;
main()
{
cout << "Hello World!" << ;
} |
I used Buzz's tutorials, which are video tutorials by the way, and thats how he wrote it.
I get this error saying I have no submain therefore the program can't be compiled and run properly. Any help?
Edit:
This is how I built the program this time, it ran, but just exited right away..
| Code: |
#include <iostream>
using namespace std;
sub main()
{
cout << "Hello World!" ;
}
End sub main |
Whats wrong?
Last edited by patsmokeswii on Tue Jan 22, 2008 11:50 am; edited 1 time in total |
|
| Back to top |
|
 |
killersamurai Expert Cheater
Reputation: 0
Joined: 10 Sep 2007 Posts: 197 Location: Colorado
|
Posted: Tue Jan 22, 2008 11:22 am Post subject: |
|
|
| You need int or void in front of main. Also, you need to put something after the <<. If not, you don't need it. |
|
| Back to top |
|
 |
hcavolsdsadgadsg I'm a spammer
Reputation: 26
Joined: 11 Jun 2007 Posts: 5801
|
Posted: Tue Jan 22, 2008 2:22 pm Post subject: |
|
|
how the hell did you manage to compile that?
| Code: | #include <iostream>
int main(void)
{
std::cout << "Hello world!";
return 0;
} |
|
|
| Back to top |
|
 |
patsmokeswii Grandmaster Cheater Supreme
Reputation: 0
Joined: 26 Aug 2007 Posts: 1039 Location: Perth Amboy, NJ
|
Posted: Tue Jan 22, 2008 3:04 pm Post subject: |
|
|
Easy, by pressing F5 XD.
It compiles and runs the program.
But, I might just get another compiler. |
|
| Back to top |
|
 |
HomerSexual Grandmaster Cheater Supreme
Reputation: 5
Joined: 03 Feb 2007 Posts: 1657
|
Posted: Tue Jan 22, 2008 3:25 pm Post subject: |
|
|
| Code: | #include <iostream>
int main()
{
std::cout << "Hello CEF\n";
std::cin.get();
return 0;
} |
You do not use vb functions such as sub main
You use int preferably so you have a return value. This means if the commands are run successfully the program will return a value of 0. If not, something went wrong. _________________
|
|
| Back to top |
|
 |
patsmokeswii Grandmaster Cheater Supreme
Reputation: 0
Joined: 26 Aug 2007 Posts: 1039 Location: Perth Amboy, NJ
|
Posted: Tue Jan 22, 2008 3:29 pm Post subject: |
|
|
| blankrider wrote: | | Code: | #include <iostream>
int main()
{
std::cout << "Hello CEF\n";
std::cin.get();
return 0;
} |
You do not use vb functions such as sub main
You use int preferably so you have a return value. This means if the commands are run successfully the program will return a value of 0. If not, something went wrong. |
I get so many errors with that one though. The only one that works is the first one, but it just instantly closes. |
|
| Back to top |
|
 |
hcavolsdsadgadsg I'm a spammer
Reputation: 26
Joined: 11 Jun 2007 Posts: 5801
|
Posted: Tue Jan 22, 2008 4:34 pm Post subject: |
|
|
| post the errors. |
|
| Back to top |
|
 |
Noz3001 I'm a spammer
Reputation: 26
Joined: 29 May 2006 Posts: 6220 Location: /dev/null
|
Posted: Tue Jan 22, 2008 5:33 pm Post subject: |
|
|
lol, thats what you get when you learn VB 1st....
Rofl |
|
| Back to top |
|
 |
patsmokeswii Grandmaster Cheater Supreme
Reputation: 0
Joined: 26 Aug 2007 Posts: 1039 Location: Perth Amboy, NJ
|
Posted: Tue Jan 22, 2008 5:36 pm Post subject: |
|
|
OK, here it is:
| Code: | | 'Sub Main' was not found in 'project 1' |
Thats the error I get.
Edit: Noz, I didn't learn VB first. To make it work, I had to put that.. I don't know why... that was the only way I wouldn't get the error.
I am just starting to learn now, I have never ever studied VB... |
|
| Back to top |
|
 |
Noz3001 I'm a spammer
Reputation: 26
Joined: 29 May 2006 Posts: 6220 Location: /dev/null
|
Posted: Tue Jan 22, 2008 5:44 pm Post subject: |
|
|
| You ARE using a C++ compiler right? |
|
| Back to top |
|
 |
patsmokeswii Grandmaster Cheater Supreme
Reputation: 0
Joined: 26 Aug 2007 Posts: 1039 Location: Perth Amboy, NJ
|
Posted: Tue Jan 22, 2008 6:26 pm Post subject: |
|
|
| noz3001 wrote: | | You ARE using a C++ compiler right? |
M.V.S. '08
Why? |
|
| Back to top |
|
 |
Noz3001 I'm a spammer
Reputation: 26
Joined: 29 May 2006 Posts: 6220 Location: /dev/null
|
Posted: Tue Jan 22, 2008 6:35 pm Post subject: |
|
|
| Code: | #include <iostream>
using namespace std;
sub main()
{
cout << "Hello World!" ;
}
End sub main |
If that compiles in it..... ;
| Code: | #include <iostream>
int main()
{
std::cout << "Hello CEF\n";
std::cin.get();
return 0;
} |
But that doesn't...;
It simply isn't the correct compiler. |
|
| Back to top |
|
 |
hcavolsdsadgadsg I'm a spammer
Reputation: 26
Joined: 11 Jun 2007 Posts: 5801
|
Posted: Tue Jan 22, 2008 6:37 pm Post subject: |
|
|
| just take a picture of these errors, and don't crop it so we can see the IDE. Because I don't know how it's possible for that one snippet to even think about compiling. |
|
| Back to top |
|
 |
wunder312355 Grandmaster Cheater
Reputation: -1
Joined: 14 May 2007 Posts: 568
|
Posted: Tue Jan 22, 2008 6:52 pm Post subject: |
|
|
This should work 100%
Its the bare minimum using namespace.
| Code: | #include <iostream>
using namespace std;
int main()
{
cout << "Hello World!" << endl;
system("pause");
} |
|
|
| Back to top |
|
 |
atom0s Moderator
Reputation: 205
Joined: 25 Jan 2006 Posts: 8587 Location: 127.0.0.1
|
Posted: Tue Jan 22, 2008 8:26 pm Post subject: |
|
|
| thefun25 wrote: | This should work 100%
Its the bare minimum using namespace.
| Code: | #include <iostream>
using namespace std;
int main()
{
cout << "Hello World!" << endl;
system("pause");
} |
|
You should avoid using syste("pause") to catch input to "freeze" the console from closing. This creates a huge overhead in your program and performance loss occurs.
http://www.gidnetwork.com/b-61.html
Instead, use:
| Code: | cin.ignore();
cin.sync(); |
_________________
- Retired. |
|
| Back to top |
|
 |
|