CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Page 2 of 3 FirstFirst 123 LastLast
Results 16 to 30 of 43
  1. #16
    Join Date
    Aug 2002
    Location
    Cluj-Napoca,Romania
    Posts
    3,496

    Re: Namespace and stdafx.h

    Quote 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

  2. #17
    Xeon's Avatar
    Xeon is offline Want me to ban you?! Power Poster
    Join Date
    Jul 2000
    Location
    Singapore
    Posts
    4,195

    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

  3. #18
    Join Date
    Aug 2002
    Location
    Cluj-Napoca,Romania
    Posts
    3,496

    Re: Namespace and stdafx.h

    Quote 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

  4. #19
    Xeon's Avatar
    Xeon is offline Want me to ban you?! Power Poster
    Join Date
    Jul 2000
    Location
    Singapore
    Posts
    4,195

    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

  5. #20
    Join Date
    Aug 2002
    Location
    Cluj-Napoca,Romania
    Posts
    3,496

    Re: Namespace and stdafx.h

    Quote 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

  6. #21
    Xeon's Avatar
    Xeon is offline Want me to ban you?! Power Poster
    Join Date
    Jul 2000
    Location
    Singapore
    Posts
    4,195

    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

  7. #22
    Xeon's Avatar
    Xeon is offline Want me to ban you?! Power Poster
    Join Date
    Jul 2000
    Location
    Singapore
    Posts
    4,195

    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

  8. #23
    Join Date
    Aug 2002
    Location
    Cluj-Napoca,Romania
    Posts
    3,496

    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

  9. #24
    Xeon's Avatar
    Xeon is offline Want me to ban you?! Power Poster
    Join Date
    Jul 2000
    Location
    Singapore
    Posts
    4,195

    Re: Namespace and stdafx.h

    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.
    "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

  10. #25
    Join Date
    Oct 2002
    Location
    Timisoara, Romania
    Posts
    14,360

    Re: Namespace and stdafx.h

    Quote 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:
    Quote Originally Posted by Xeon
    Is this the latest requirement in the C++ standard?
    Marius Bancila
    Home Page
    My CodeGuru articles

    I do not offer technical support via PM or e-mail. Please use vbBulletin codes.

  11. #26
    Join Date
    Feb 2005
    Location
    Normandy in France
    Posts
    4,590

    Re: Namespace and stdafx.h

    Quote 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()!

  12. #27
    Join Date
    Jun 2002
    Posts
    1,417

    Re: Namespace and stdafx.h

    Quote 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!

  13. #28
    Join Date
    Oct 2002
    Location
    Timisoara, Romania
    Posts
    14,360

    Re: Namespace and stdafx.h

    AFAIK Comeau coverts C++ to C and then compiles the output with a C compiler.
    Marius Bancila
    Home Page
    My CodeGuru articles

    I do not offer technical support via PM or e-mail. Please use vbBulletin codes.

  14. #29
    Join Date
    May 2000
    Location
    KY, USA
    Posts
    18,652

    Re: Namespace and stdafx.h

    Quote 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.

  15. #30
    Join Date
    Jun 2002
    Posts
    1,417

    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.

Page 2 of 3 FirstFirst 123 LastLast

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured