-
November 2nd, 2005, 08:49 AM
#16
Re: Namespace and stdafx.h
Originally Posted by Xeon
Maybe I gotta skip this for now or else I'll stress out myself.
At some point you'll have enough skipped things and you'll have to deal with them all.
Postponning things is pretty similar with how the flush works. From time to time the stream has to deal with all the information it collected but not yet written on the physical device.
Hope it helped.
Har Har
-
November 2nd, 2005, 09:20 AM
#17
Re: Namespace and stdafx.h
From PadexArt:
At some point you'll have enough skipped things and you'll have to deal with them all.
Nah, I intend to deal with this buffer flushing later on in the book, during operator overloading etc.
By the way, guys......I'm currently using Dev C++. For those of you who've used this compiler before, here's my code :
Code:
#include <cstdlib>
#include <iostream>
using namespace std;
int main()
{
cout << "I'm back!" << endl;
return 0;
}
My question is : in C++ nowadays, is it a MUST for the main() function to return an integer value? Because when I make it a void main() and return nothing, the compiler gave me the following error :
C:\C++\Test\Project1.cpp `main' must return `int'
Is this the latest requirement in the C++ standard?
Thanks!
Xeon.
"Hell is calling for you!" - Rufus, from Valkyrie Profile 2 : Silmeria
"I'm getting tired of you devils.....finishing strike......Final Blast!" - Arngrim, from Valkyrie Profile 2 : Silmeria
-
November 2nd, 2005, 09:23 AM
#18
Re: Namespace and stdafx.h
Originally Posted by Xeon
Is this the latest requirement in the C++ standard?
Yes, and MinGW ( the compiler shipped with DevC++) is compliant enough to complain about it.
Har Har
-
November 2nd, 2005, 09:28 AM
#19
Re: Namespace and stdafx.h
From PadexArt:
Yes, and MinGW ( the compiler shipped with DevC++) is compliant enough to complain about it.
My! Good! That means that Dev C++ is so strict that it's going to force me to have the best of programming habits totally compliant with the C++ specification, eh?
One more question : I notice that the moment I run my program from Dev C++, the console window appears and closes instantly.
I found the solution in cin.get(); added at the very last line. After adding this, the console window stayed until I hit the enter key.
What does this cin.get() do? Stop the console window from closing immediately it is launched?
Thanks, Padex!
Xeon.
"Hell is calling for you!" - Rufus, from Valkyrie Profile 2 : Silmeria
"I'm getting tired of you devils.....finishing strike......Final Blast!" - Arngrim, from Valkyrie Profile 2 : Silmeria
-
November 2nd, 2005, 09:35 AM
#20
Re: Namespace and stdafx.h
Originally Posted by Xeon
What does this cin.get() do? Stop the console window from closing immediately it is launched?
Yes, that is its purpose in this context. I prefer using _getch from <conio.h> (you do not have to hit enter to make the console close) but I'm not sure how portable is that function.
But this is not what get() was designed for. The function retrieves a character from the stream it is invoked on.
Har Har
-
November 2nd, 2005, 09:43 AM
#21
Re: Namespace and stdafx.h
From P. Art:
But this is not what it was designed for. cin.get() waits for a character to be retrieved from the standard input stream.
I see now; so as long as I don't ****ing enter any character, the window will never close. Which is what I want. Which in turn boosts my ego.
Thanks for the help, P. Art!
Xeon.
"Hell is calling for you!" - Rufus, from Valkyrie Profile 2 : Silmeria
"I'm getting tired of you devils.....finishing strike......Final Blast!" - Arngrim, from Valkyrie Profile 2 : Silmeria
-
November 2nd, 2005, 10:01 AM
#22
Re: Namespace and stdafx.h
By the way, one more thing, guys :
Code:
#include <iostream>
using namespace std;
int main()
{
double dCelsius = 0.0, dFah = 0.0;
cout << "Enter the celsius temperature to be converted to Fahrenheit :\n";
cin >> dCelsius;
dFah = (dCelsius * 1.8) + 32;
cout << "The Fahrenheit equivalent of " << dCelsius << " celsius is " << dFah;
return 0;
}
The problem is : when launched, the program closes immediately after it is launched. Even adding "cin.get()" this time is useless.
So, I added "cin >> dFah" to keep the window there, as in :
Code:
#include <iostream>
using namespace std;
int main()
{
double dCelsius = 0.0, dFah = 0.0;
cout << "Enter the celsius temperature to be converted to Fahrenheit :\n";
cin >> dCelsius;
dFah = (dCelsius * 1.8) + 32;
cout << "The Fahrenheit equivalent of " << dCelsius << " celsius is " << dFah;
cin >> dFah;
return 0;
}
This fixes the problem of the vanishing console window, but it also means that the console window can never be closed unless the user uses the mouse to click the X button at the top-right corner of the console window.
(in console windows, normally you can end the program by pressing enter when all the work has been done)
Is there a natural fix for this?(I'm using Dev C++)
Thanks!
Xeon.
"Hell is calling for you!" - Rufus, from Valkyrie Profile 2 : Silmeria
"I'm getting tired of you devils.....finishing strike......Final Blast!" - Arngrim, from Valkyrie Profile 2 : Silmeria
-
November 2nd, 2005, 10:12 AM
#23
Re: Namespace and stdafx.h
Code:
#include <iostream>
using namespace std;
int main()
{
double dCelsius = 0.0, dFah = 0.0;
cout << "Enter the celsius temperature to be converted to Fahrenheit: ";
cin >> dCelsius;
dFah = (dCelsius * 1.8) + 32;
cout << "The Fahrenheit equivalent of " << dCelsius << " celsius is: " << dFah;
cin.sync();
cin.get();
return 0;
}
Har Har
-
November 2nd, 2005, 10:16 AM
#24
-
November 2nd, 2005, 11:05 AM
#25
Re: Namespace and stdafx.h
Originally Posted by Xeon
By the way, pray God....what does the cin.sync() do?
Have you heard of MSDN? Read it!
And please make a forum search before asking questions like:
Originally Posted by Xeon
Is this the latest requirement in the C++ standard?
-
November 2nd, 2005, 12:27 PM
#26
Re: Namespace and stdafx.h
Originally Posted by Xeon
Awesome, Padex! Works smoothly as ****! OMFG. Look at this : just because I'm using a diferent compiler from the book, I gotta go through all these ****.
I know Visual C++ don't require all these stuff! What the?!
By the way, pray God....what does the cin.sync() do?
Thanks!
Xeon.
The synchronisation is necessary because std::cin does not read the newline character after the number input. And cin.get returns that newline character without needing to get input from the user.
I hope that VC++ 6.0 exposes that behavior! Even very old non-compliant compilers, written years and years before the standard!
RHIDE is an IDE for DJGPP (the GNU C++ compiler for DOS32).
The compiler is very ISO compliant, and is probably in second place as the most compliants compilers (Comeau is the first).
"inherit to be reused by code that uses the base class, not to reuse base class code", Sutter and Alexandrescu, C++ Coding Standards.
Club of lovers of the C++ typecasts cute syntax: Only recorded member.
Out of memory happens! Handle it properly!
Say no to g_new()!
-
November 2nd, 2005, 12:37 PM
#27
Re: Namespace and stdafx.h
Originally Posted by SuperKoko
(Comeau is the first).
Comeau is not a compiler -- its a preprocessor for C compilers. It can't even compile the C code it spits out!
-
November 2nd, 2005, 05:44 PM
#28
Re: Namespace and stdafx.h
AFAIK Comeau coverts C++ to C and then compiles the output with a C compiler.
-
November 3rd, 2005, 01:56 AM
#29
Re: Namespace and stdafx.h
Originally Posted by stober
Comeau is not a compiler -- its a preprocessor for C compilers. It can't even compile the C code it spits out!
Well...
Comeau C/C++ is a command line driven C and C++ compiler that generates platform specific and C compiler specific C as its object code (the generated C code won't work on another platform, as it is CPU, OS and C compiler specific, and furthermore, it is not standalone). It then transparently invokes a particular C compiler that we've specifically ported it to (again, it won't work with one we haven't ported it to -- such porting must be done by Comeau since particulars must be coded into the compiler and library itself). Note closely that this is not preprocessing, but compiling. The Comeau C/C++ front-end first does full "C-style" preprocessing (#include, #define, etc.), as usual. That results in a normal translation unit, upon which Comeau C/C++ then does normal and full syntax, semantic and error checking. Next, the input C++ program (or C program in C mode) is translated into a machine independent intermediate language (IL), as is usually done by compilers. So, in effect, the original C++ (or C in C mode) source code is effectively gone at this point.
Last edited by Andreas Masur; November 3rd, 2005 at 02:00 AM.
-
November 3rd, 2005, 06:34 AM
#30
Re: Namespace and stdafx.h
It then transparently invokes a particular C compiler
That is exactly what I said -- Comdeau is not a compiler, just a preprocessor. You have to have some other compiler installed on your computer.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|