| View previous topic :: View next topic |
| Author |
Message |
crayzbeef Expert Cheater
Reputation: 0
Joined: 21 Jan 2007 Posts: 101
|
Posted: Wed Aug 06, 2008 4:54 pm Post subject: |
|
|
DONT INCLUDE THE WHOLE NAMESPACE IF YOUR JUST USING COUT OR CIN!
using std::cout
or just say
std::cout << "Your all dumbasses learn C++ plz:
|
|
| Back to top |
|
 |
jackyyll Expert Cheater
Reputation: 0
Joined: 28 Jan 2008 Posts: 143 Location: here
|
Posted: Wed Aug 06, 2008 5:05 pm Post subject: |
|
|
| I'm pretty sure VC++ still includes the iosteam.h file (Which doesn't use the std namespace). Also, main doesn't explicitly need to be int, it can be void but shouldn't be done really.
|
|
| Back to top |
|
 |
atom0s Moderator
Reputation: 205
Joined: 25 Jan 2006 Posts: 8588 Location: 127.0.0.1
|
Posted: Wed Aug 06, 2008 5:15 pm Post subject: |
|
|
| jackyyll wrote: | | I'm pretty sure VC++ still includes the iosteam.h file (Which doesn't use the std namespace). Also, main doesn't explicitly need to be int, it can be void but shouldn't be done really. |
The compiler doesn't magically add includes. You have to include them yourself. If you want to use iostream, you must add it to your file(s) that are using it.
The main function for a console is 'int main' as standard. No it doesn't have to be int but that is C standard.
_________________
- Retired. |
|
| Back to top |
|
 |
jackyyll Expert Cheater
Reputation: 0
Joined: 28 Jan 2008 Posts: 143 Location: here
|
Posted: Wed Aug 06, 2008 5:52 pm Post subject: |
|
|
| Wiccaan wrote: | | jackyyll wrote: | | I'm pretty sure VC++ still includes the iosteam.h file (Which doesn't use the std namespace). Also, main doesn't explicitly need to be int, it can be void but shouldn't be done really. |
The compiler doesn't magically add includes. You have to include them yourself. If you want to use iostream, you must add it to your file(s) that are using it.
The main function for a console is 'int main' as standard. No it doesn't have to be int but that is C standard. |
I meant that the iosteam.h file is still included in the includes directory even though it's pretty much deprecated.
|
|
| Back to top |
|
 |
Jani Grandmaster Cheater
Reputation: 2
Joined: 29 Dec 2006 Posts: 804
|
Posted: Thu Aug 07, 2008 3:51 am Post subject: |
|
|
| oib111 wrote: | | How do you suggest then Jani? | I do NOT suggest pausing. The original poster didn't pause execution, but HalfPrime suggested that he should do that. I suggest that you DON'T pause execution. I was referring to pausing at the end of the program in general with the term "that way." Sorry for making my point a bit unclear.
Anyway.. If you MUST pause your program I second Wiccaan on that: | Code: | std::cin.sync();
std::cin.ignore(); |
|
|
| Back to top |
|
 |
HalfPrime Grandmaster Cheater
Reputation: 0
Joined: 12 Mar 2008 Posts: 532 Location: Right there...On your monitor
|
Posted: Thu Aug 07, 2008 9:34 am Post subject: |
|
|
And force people to run it through the console? No, thank you.
_________________
|
|
| Back to top |
|
 |
Heartless I post too much
Reputation: 0
Joined: 03 Dec 2006 Posts: 2436
|
Posted: Thu Aug 07, 2008 3:40 pm Post subject: Re: C++ error |
|
|
| famousmassacre1 wrote: | i keep getting an error on this code but i cant find whats wrong
| Code: |
// This is a comment
// This program will accept and display their sum
#include <iostream.h>
void main()
{
// Define variables
float num1;
float num2;
float total;
// Enter data for variables
cout << "10";
cin >> num1;
cout << "9";
cin >> num2;
// Add the two numbers together
total = num1 + num2;
// Display the result
cout << "The sum of the numbers = " << total;
} | [/code] |
you forgot...
| Code: | | using namespace std; |
or you'll haveto add...
to your code.
_________________
What dosen't kill you, usually does the second time. |
|
| Back to top |
|
 |
kitterz Grandmaster Cheater Supreme
Reputation: 0
Joined: 24 Dec 2007 Posts: 1268
|
Posted: Thu Aug 07, 2008 3:44 pm Post subject: |
|
|
| crayzbeef wrote: | DONT INCLUDE THE WHOLE NAMESPACE IF YOUR JUST USING COUT OR CIN!
using std::cout
or just say
std::cout << "Your all dumbasses learn C++ plz: |
you mean
| Code: | | std::cout << "Your all dumbasses learn C++ plz" |
REmember the ending quote. You need to brush up on your C++
|
|
| Back to top |
|
 |
jackyyll Expert Cheater
Reputation: 0
Joined: 28 Jan 2008 Posts: 143 Location: here
|
Posted: Thu Aug 07, 2008 4:19 pm Post subject: |
|
|
| kitterz wrote: | | crayzbeef wrote: | DONT INCLUDE THE WHOLE NAMESPACE IF YOUR JUST USING COUT OR CIN!
using std::cout
or just say
std::cout << "Your all dumbasses learn C++ plz: |
you mean
| Code: | | std::cout << "Your all dumbasses learn C++ plz" |
REmember the ending quote. You need to brush up on your C++ |
You forgot your semi-colon, maybe you need to brush up too?
|
|
| Back to top |
|
 |
hcavolsdsadgadsg I'm a spammer
Reputation: 26
Joined: 11 Jun 2007 Posts: 5801
|
Posted: Thu Aug 07, 2008 4:23 pm Post subject: |
|
|
| kitterz wrote: | | crayzbeef wrote: | DONT INCLUDE THE WHOLE NAMESPACE IF YOUR JUST USING COUT OR CIN!
using std::cout
or just say
std::cout << "Your all dumbasses learn C++ plz: |
you mean
| Code: | | std::cout << "Your all dumbasses learn C++ plz" |
REmember the ending quote. You need to brush up on your C++ |
you mean
| Code: | | std::cout << "Your all dumbasses learn C++ plz"; |
REmember the ending semicolon. You need to brush up on your C++
also: you're
|
|
| Back to top |
|
 |
Typhoon808 Expert Cheater
Reputation: 0
Joined: 27 Mar 2008 Posts: 175 Location: Wales
|
Posted: Thu Aug 07, 2008 4:26 pm Post subject: |
|
|
Also it's you're not your.
|
|
| Back to top |
|
 |
Jani Grandmaster Cheater
Reputation: 2
Joined: 29 Dec 2006 Posts: 804
|
Posted: Fri Aug 08, 2008 3:34 am Post subject: |
|
|
| HalfPrime wrote: | | And force people to run it through the console? No, thank you. | Running a program as a scheduled task and leave it waiting for input? No, thank you.
If you check any a bit more "professional" console program, you'll notice that they don't wait for a closing input. To name some programs (from M$ for example) help.exe, ipconfig.exe, rename.exe, and so on.. Note that we're talking about console applications.
Personally I run hella lot stuff from console, even programs with GUI. For example, my Firefox is running from console atm. And it's freaking annoying when you've to press any key to close a program.
PS: slovach & co.: you forgot to include the header containing std::cout object :P
|
|
| Back to top |
|
 |
HalfPrime Grandmaster Cheater
Reputation: 0
Joined: 12 Mar 2008 Posts: 532 Location: Right there...On your monitor
|
Posted: Fri Aug 08, 2008 8:34 am Post subject: |
|
|
We're not talking about scheduled tasks. We're talking about stand-alone console progs. They can be done either way, but 99/100 users would prefer press any key to exit.
_________________
|
|
| Back to top |
|
 |
Jani Grandmaster Cheater
Reputation: 2
Joined: 29 Dec 2006 Posts: 804
|
Posted: Fri Aug 08, 2008 3:27 pm Post subject: |
|
|
| HalfPrime wrote: | | We're not talking about scheduled tasks. | It was just an example. Standalone console programs are widely used as scheduled tasks with some params.
Please mention any "professional" software requiring "press any key" at the end of execution. Just to name a few more programs, which close without nagging: fsum.exe*1, nmap.exe*2, lame.exe*3, rar.exe*4, java.exe*5, javac.exe*5, cl.exe*6... :) Actually to be honest, I can't figure out any "professional" program nagging about "press any key to exit" with an exception of bootloaders/BIOSes displaying an error message.
Only place where I'd like to have that nag is when your computer would restart after the nag -> the message couldn't be seen.
Because of Windows' XP (and Vista?) do have a feature of an auto closing cmd.exe doesn't mean that you should pause your program before exit.
| HalfPrime wrote: | | They can be done either way, but 99/100 users would prefer press any key to exit. | Guess if I made a poll here with people making their first hello world's, yeah that might be true. But go and make a poll, eg. on M$' newsgroup or some other forum with a bit more "experienced" people and you'll notice that it's totally the opposite.
References:
*1 http://www.slavasoft.com/fsum/
*2 http://nmap.org/
*3 http://lame.sourceforge.net/
*4 http://www.rarlab.com/
*5 http://java.sun.com/
*6 http://www.microsoft.com/
|
|
| Back to top |
|
 |
|