Thread: Dev-C++ works, but Visual C++ do not ???

  1. #1
    Registered User
    Join Date
    Sep 2010
    Posts
    90

    Dev-C++ works, but Visual C++ do not ???

    Could someone show me what is wrong with this code in-order to make it work when compiling under Visual C++ 2008.

    It will compile and run "PERFECTLY" under Dev-C++ 5.0. It gives no warnings and no errors because the code is A-OK . .. but under Visual C++ 2008 it gives me a zillion errors and warnings.

    It's like nearly everything I try under Dev-C++ 5.0 that turns out perfect, Visual C++ 2008 always got something to say about it by dishing out a bunch of error and warning, than it will not compile the code.

    I placed the complete Visual C++ 2008 build-log (error report) at the bottom of the code in the code section below.

    Code:
    // ...............................................  How-to switch-CASE.cpp
    #include <iostream>
    #include <iomanip>
    
    using namespace std;        // for iostream
    using std::cout;
    using std::cin;
    using std::endl;
    
    using std::setprecision;    // for iomanip
    using std::fixed;
    
    int main()
    {
    	int product;
    	int quantity;
    	double product1 = 23.84;
    	double product2 = 13.5;
    	double product3 = 119.76;
    	double product4 = 251.44;
    	double product5 = 13.74;
    	double total = 0;
    
    /////////////////////////////
    /////////////////////////////   step - 1
    /////////////////////////////
    
    cout
    << "\nProduct 1 =   $  " << product1
    << "\nProduct 2 =   $  " << fixed << setprecision( 2) << product2
    << "\nProduct 3 =   $ " << product3
    << "\nProduct 4 =   $ " << product4
    << "\nProduct 5 =   $  " << product5
    << endl << endl;
    
    
    total = total + ( product1 + product2 + product3 + product4 + product5);
    cout << total << endl << endl << endl;
    
    total= 0;
    
    /////////////////////////////
    /////////////////////////////   step - 2
    /////////////////////////////
    
    	cout << "Enter product number 1 - 5 : ";
    
    	while (!(cin >> product))
    {
                cout << "\nPlease enter ( 1 - 5 ) or to EXIT type -1\n\n" << endl;
                cin.clear();
                    cin.ignore(std::numeric_limits<std::streamsize>::max(), '\n');
                    cout << "Enter product number 1 - 5 : ";
    }
    
    /////////////////////////////
    /////////////////////////////   step - 3
    /////////////////////////////
    
    	               while ( product != -1 )
    	               {
    		                      switch ( product )
    		                  {
    		                              case 1:
    			                             cout << "\n\nEnter quantity 
    
    sold : ";
    			                             cin >> quantity;
                                             cout << endl;
    
    			                             total = total + ( product1 * 
    
    quantity );
    			                             break;
    
    		                              case 2:
    			                             cout << "\n\nEnter quantity 
    
    sold : ";
    			                             cin >> quantity;
                                             cout << endl;
    
    			                             total = total + ( product2 * 
    
    quantity );
    			                             break;
    
    		                              case 3:
    			                             cout << "\n\nEnter quantity 
    
    sold : ";
    			                             cin >> quantity;
                                             cout << endl;
    
    			                             total = total + ( product3 * 
    
    quantity );
    			                             break;
    
    		                              case 4:
    			                             cout << "\n\nEnter quantity 
    
    sold : ";
    			                             cin >> quantity;
                                             cout << endl;
    
    			                             total = total + ( product4 * 
    
    quantity );
    			                             break;
    
    		                              case 5:
    			                             cout << "\n\nEnter quantity 
    
    sold : ";
    			                             cin >> quantity;
                                             cout << endl;
    
    			                             total = total + ( product5 * 
    
    quantity );
    			                             break;
    
    		                      case '\n':
    		                      case '\t':
    		                      case ' ':
                            break;
    
                                 default: // catch any other characters
                  cout << "\nPlease enter ( 1 - 5 ) or to EXIT type -1\n\n" << endl;
                            break;
    		              }
    /////////////////////////////
    /////////////////////////////   step - 4
    /////////////////////////////   Pick up from "quanity sold" == ERROR correction
    
    	   cout << "Enter product number 1 - 5 : ";
    
       while (!(cin >> product))
     {
            cout << "Incorrect entry:  Try again\n" << endl;
            cin.clear();
    
            cin.ignore(std::numeric_limits<std::streamsize>::max(), '\n');
    
            cout << "Enter product number 1 - 5 : ";
     } //endWHILE
    
    /////////////////////////////
    /////////////////////////////   step - 5
    /////////////////////////////
    
    	}
    	   cout << "\n\n\nT O T A L :    $" << fixed << setprecision( 2 )
    		    << total << endl<< endl<< endl;
    
    system("pause");
    system ("CLS");
    return main();
    
    return 0;
    }
    
    
    //  ------ Build started: Project: vc--switch-CASE, Configuration: Debug Win32 
    
    ------
    //  Compiling...
    //  switch-CASE.cpp
    //  c:\_vc\vc--switch-case\vc--switch-case\switch-case.cpp(69) : error C2039: 
    
    'numeric_limits' : is not a member of 'std'
    //  c:\_vc\vc--switch-case\vc--switch-case\switch-case.cpp(69) : error C2065: 
    
    'numeric_limits' : undeclared identifier
    //  c:\_vc\vc--switch-case\vc--switch-case\switch-case.cpp(69) : error C2275: 
    
    'std::streamsize' : illegal use of this type as an expression
    //  c:\_vc\vc--switch-case\vc--switch-case\switch-case.cpp(69) : error C2780: 
    
    'const _Ty &std::max(const _Ty &,const _Ty &,_Pr)' : expects 3 arguments - 0 
    
    provided
    //          d:\program files\microsoft visual studio 
    
    9.0\vc\include\xutility(3390) : see declaration of 'std::max'
    //  c:\_vc\vc--switch-case\vc--switch-case\switch-case.cpp(69) : error C2780: 
    
    'const _Ty &std::max(const _Ty &,const _Ty &)' : expects 2 arguments - 0 provided
    //          d:\program files\microsoft visual studio 
    
    9.0\vc\include\xutility(3382) : see declaration of 'std::max'
    //  c:\_vc\vc--switch-case\vc--switch-case\switch-case.cpp(141) : error C2039: 
    
    'numeric_limits' : is not a member of 'std'
    //  c:\_vc\vc--switch-case\vc--switch-case\switch-case.cpp(141) : error C2065: 
    
    'numeric_limits' : undeclared identifier
    //  c:\_vc\vc--switch-case\vc--switch-case\switch-case.cpp(141) : error C2275: 
    
    'std::streamsize' : illegal use of this type as an expression
    //  c:\_vc\vc--switch-case\vc--switch-case\switch-case.cpp(141) : error C2780: 
    
    'const _Ty &std::max(const _Ty &,const _Ty &,_Pr)' : expects 3 arguments - 0 
    
    provided
    //          d:\program files\microsoft visual studio 
    
    9.0\vc\include\xutility(3390) : see declaration of 'std::max'
    //  c:\_vc\vc--switch-case\vc--switch-case\switch-case.cpp(141) : error C2780: 
    
    'const _Ty &std::max(const _Ty &,const _Ty &)' : expects 2 arguments - 0 provided
    //          d:\program files\microsoft visual studio 
    
    9.0\vc\include\xutility(3382) : see declaration of 'std::max'
    //  Build log was saved at 
    
    "file://c:\_vc\vc--switch-CASE\vc--switch-CASE\Debug\BuildLog.htm"
    //  vc--switch-CASE - 10 error(s), 0 warning(s)
    //  ========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========

  2. #2

  3. #3
    Registered User
    Join Date
    Sep 2010
    Posts
    90
    I only had to include the <limits> header ... but do anyone know why do it work automatically in Dev C++ and not Visual C++ ?

    I am new to C++ and did not have a clue of what to do. Now I know I can find the missing header by understanding what's in the error-list or search MS Support

    Thanks a millon rags_to_riches

  4. #4
    C++まいる!Cをこわせ!
    Join Date
    Oct 2007
    Location
    Inside my computer
    Posts
    24,654
    Some headers tend to include others. It just happens that sometimes, they include a needed header behind the scenes.
    This does not guarantee it will work right, however. Different implementations include different headers. In order to use something, you should always include the appropriate headers and not rely on it being included from some other header.
    Quote Originally Posted by Adak View Post
    io.h certainly IS included in some modern compilers. It is no longer part of the standard for C, but it is nevertheless, included in the very latest Pelles C versions.
    Quote Originally Posted by Salem View Post
    You mean it's included as a crutch to help ancient programmers limp along without them having to relearn too much.

    Outside of your DOS world, your header file is meaningless.

  5. #5
    The larch
    Join Date
    May 2006
    Posts
    3,573
    I only had to include the <limits> header ... but do anyone know why do it work automatically in Dev C++ and not Visual C++ ?
    Which standard header includes which other standard headers is completely up to the implementation.

    DevC++ comes with an old version of GCC compiler. Newer versions also complain about missing numeric_limits. If you want to use a standard library class or function, you'll be better off including the necessary header.
    I might be wrong.

    Thank you, anon. You sure know how to recognize different types of trees from quite a long way away.
    Quoted more than 1000 times (I hope).

  6. #6
    Algorithm Dissector iMalc's Avatar
    Join Date
    Dec 2005
    Location
    New Zealand
    Posts
    6,318
    If you think MSVC is picky about missing includes, just wait until you try GCC!
    It sounds like Dev C++ will let you get away with murder. Everyone seems to say to toss it out nowdays and use either Code Blocks, or VS2008 Express (2010 if you're Elysia)
    My homepage
    Advice: Take only as directed - If symptoms persist, please see your debugger

    Linus Torvalds: "But it clearly is the only right way. The fact that everybody else does it some other way only means that they are wrong"

  7. #7
    Registered User
    Join Date
    Sep 2010
    Posts
    90
    WoW! What a great Forum. So that's what precompiled header is all about. How do we turn-off or completely remove the precompiled header function? Now I want to turn off everything so I can include only what is needed "and" be assured that there is no underlying monitoring going on or foot-print being added to the final executable. I even want to turn off hints and tool-tips and watch VS or CB run like a rocket. The only thing Dollar Bill want to share is folders, so I ask you guy. Who can do that, Code Block, VS2008 or VS2010? If we have no control over foot-print, can it be removed manually? Just like in networking, I read that a call to Window_Size and/or grabbing the foot-print of the gateway OS, a hacker can learn how many nodes your network have, so foot-prints will be the first to GO, if possible. Starting at rock bottom, with no favors added by the IDE/compiler is cool with me. I'll even try an open-source solution if I have to. Are there any? I'm downloading Code Block for starters. C++ is additive, isn't it
    Last edited by sharris; 10-04-2010 at 09:49 AM. Reason: Bad spelling mostly

  8. #8
    C++まいる!Cをこわせ!
    Join Date
    Oct 2007
    Location
    Inside my computer
    Posts
    24,654
    Debugging information is added to the executable in order to help debugging it. Otherwise you will find it difficult. Nothing else is added. Toolstips and stuff help productivity and does not add anything to your executable.
    Switch to release mode when you want to ship your program to remove that.
    Precompiled headers speed up the compilation, so that's not wise to turn off if you want it to run like a rocket. Otherwise a quick google search will net you the info you need.
    Quote Originally Posted by Adak View Post
    io.h certainly IS included in some modern compilers. It is no longer part of the standard for C, but it is nevertheless, included in the very latest Pelles C versions.
    Quote Originally Posted by Salem View Post
    You mean it's included as a crutch to help ancient programmers limp along without them having to relearn too much.

    Outside of your DOS world, your header file is meaningless.

  9. #9
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,660
    PCH is one of the biggest sources of frustration for newbies. It is essentially pointless for student sized homework problems (a handful of files at most).

    Itīs easy enough to turn off, and then you can just forget about it for a few years.

    The real "win" for PCH is in large industrial projects which are fairly static and typically include a whole bunch of stuff "as standard".
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.

  10. #10
    C++まいる!Cをこわせ!
    Join Date
    Oct 2007
    Location
    Inside my computer
    Posts
    24,654
    It's great for the impatient. I use it projects large as well as small.
    The only problem is that it's not taught well enough. If you just understand them, then there is no problem in using them.
    Quote Originally Posted by Adak View Post
    io.h certainly IS included in some modern compilers. It is no longer part of the standard for C, but it is nevertheless, included in the very latest Pelles C versions.
    Quote Originally Posted by Salem View Post
    You mean it's included as a crutch to help ancient programmers limp along without them having to relearn too much.

    Outside of your DOS world, your header file is meaningless.

  11. #11
    'Allo, 'Allo, Allo
    Join Date
    Apr 2008
    Posts
    639
    It's easy enough to measure when they are faster and when not. Add /Bt to the additional compiler options (C/C++ -> Command Line -> Additional Options) and /time to the additional linker options (Linker -> Command Line -> Additional Options) and rebuild. For instance with the code in the OP (compile errors fixed and with <limits> added) on a default new project, precomp headers are slower for me (2x2.1Ghz, 4GB Ram, Win 7 x64):

    Precomp headers:

    Compiling...
    stdafx.cpp
    time(G:\Microsoft Visual Studio 9.0\VC\bin\c1xx.dll)=2.234s
    time(G:\Microsoft Visual Studio 9.0\VC\bin\c2.dll)=0.020s
    Compiling...
    Test.cpp
    time(G:\Microsoft Visual Studio 9.0\VC\bin\c1xx.dll)=0.078s
    time(G:\Microsoft Visual Studio 9.0\VC\bin\c2.dll)=0.020s
    Compiling manifest to resources...
    Linking...
    Pass 1: Interval #1, time = 0.062s
    Pass 2: Interval #2, time = 0.110s
    Final: Total time = 0.172s
    Embedding manifest...
    IncrPass2: Interval #1, time = 0.047s
    IncrPass2: Interval #2, time = 0.062s
    Final: Total time = 0.109s
    Build Time 0:03

    Non precomp:

    Compiling...
    Test.cpp
    time(G:\Microsoft Visual Studio 9.0\VC\bin\c1xx.dll)=0.814s
    time(G:\Microsoft Visual Studio 9.0\VC\bin\c2.dll)=0.020s
    Compiling manifest to resources...
    Linking...
    Pass 1: Interval #1, time = 0.062s
    Pass 2: Interval #2, time = 0.094s
    Final: Total time = 0.156s
    Embedding manifest...
    IncrPass2: Interval #1, time = 0.047s
    IncrPass2: Interval #2, time = 0.093s
    Final: Total time = 0.140s
    Build Time 0:01
    On the other hand with multiple files including the windows.h behemoth, precomp headers are 40% faster. Like everything else in programming, the only absolute is that there aren't any absolutes.

  12. #12
    Registered User
    Join Date
    Sep 2010
    Posts
    90
    You guys should know, Delphi was my first lang than under six months i defected to Assembler and never looked back. That was 1999. But it's funny I can't talk ASM but i can code it fairly well. What I admire about C++ is that many coders can do it all, including in-line ASM. They talk as they debug code in their heads. That takes me weeks. I stay so low i didn't even use macros. Take it from a pro, you don't learn much else being stubborn. heehee

    I stop coding for a better 9-5 in 2004, just when the heat was on that people were writing C++ or was it .NET at the speed near or equal to well written assembler, and it was proven at the win32AsmCommunity.

    From that day i wanted to learn C/C++ but never had the time until now. Now that I'm in it, I plan to turn every thing off as possible so I can turn thing back on as "I" feel needed. This is the way i learned Delphi and ASM in under a few months and I'm not about to change now but it will take longer. C++ is a tough cookie, the way I want to use it.

    Anyway, this is what I wrote to you Elysia before passing out for lack of sleep. So no reason to trash it now. Just over look the goofy parts.


    Debugging information is added to the executable in order to help debugging it. Otherwise you will find it difficult.
    Don't get me wrong. I would use the debugging facilities sometime than I would use MessageBox, if possible. It helps you debug "every step" of the way, personally. That's why I want turn it off.
    Nothing else is added.
    Do that include any foot-print for sure? MS has busted for doing wrong many times in the pass that broke a lot of hearts and empty some pockets. Also debug information will bloat the executable.
    Toolstips and stuff help productivity and does not add anything to your executable.
    I would use it until I read all. After that I can live with-out the pop-up. The faster you move the harder it works to keep up which has cause my system to slow down or hang. I have decent amount memory for a program who knows how to use it. Over-bloated code is its problem. There are better build ships that use less fuel and can maintain the speed of light. If not we'll build it.
    Switch to release mode when you want to ship your program to remove that.
    OK, Thanks
    Precompiled headers speed up the compilation, so that's not wise to turn off if you want it to run like a rocket.
    If eliminating Precompiled headers build tooooo slow, it time to try another. Benchmarking comes first.
    Otherwise a quick google search will net you the info you need.
    No need to. You gave me the low-down.

    Anyway, don't let me interrupt such a great conversation that is going into many options that can be used. I'm loving it. and Thanks a million Elysia ... With these tips it is time to do some googling so I can come back with input.
    ...

  13. #13
    C++まいる!Cをこわせ!
    Join Date
    Oct 2007
    Location
    Inside my computer
    Posts
    24,654
    Quote Originally Posted by sharris View Post
    Don't get me wrong. I would use the debugging facilities sometime than I would use MessageBox, if possible. It helps you debug "every step" of the way, personally. That's why I want turn it off.
    I'm confused. What do you want to do? Turn off debugging and use Message boxes?

    Do that include any foot-print for sure? MS has busted for doing wrong many times in the pass that broke a lot of hearts and empty some pockets. Also debug information will bloat the executable.
    Yes, but Microsoft is also a company company, so to speak. Many of their customers use their tool suite to create blazing speed programs and small foot prints, so they listen to them.
    Also, breaking stuff is not the same as always putting bloat into something. It would be equivalent to Microsoft suddenly deciding to bloat executables, which hasn't been the case AFAIK.

    I would use it until I read all. After that I can live with-out the pop-up. The faster you move the harder it works to keep up which has cause my system to slow down or hang. I have decent amount memory for a program who knows how to use it. Over-bloated code is its problem. There are better build ships that use less fuel and can maintain the speed of light. If not we'll build it.
    I don't think you can live without tooltips and intellisense. Again, it hurts your efficiency. You are not going to remember everything, and intellisense helps you on your way.
    Try without, then try with, and you should see. I don't know how to disable it though (why in the pits would I want to!?!)
    Quote Originally Posted by Adak View Post
    io.h certainly IS included in some modern compilers. It is no longer part of the standard for C, but it is nevertheless, included in the very latest Pelles C versions.
    Quote Originally Posted by Salem View Post
    You mean it's included as a crutch to help ancient programmers limp along without them having to relearn too much.

    Outside of your DOS world, your header file is meaningless.

  14. #14
    Registered User
    Join Date
    Sep 2010
    Posts
    90
    Elysia, before I join I read where you helped of a lot of people here. You deserve an explanation, but I stay crazy for fun. The foot-print thing isn't really an issue. My guest is it can help to keep people honest and not write FreeBSD programs using MS product which break the licencing agreement. As far as MS history, I just like to tease. About the size of MS OS and programs, everybody knows that the more INTEL giveth, MS takes away. Now you need to buy more memory and a bigger processors to run their latest version of anything, especially these days. But that's not really an issue for me. Deep down where it counts even hard core LINUX users still love MS more. Gnome and KDE is slow as heck in comparison to any Windows. Sure there are security issues but not if you trained your Windows, "well". That's where 3rd party C++ programs comes in It's only a love hate relationship that will never die.

    Everybody have there reasons for wanting to try uncommon things, especially computer geeks like me. I never been an common user. One of my reason is to re-capture some of that power that MS use on my machines. Simply by turning off a few things you can feel the stability and speed increase ten-folds at times, making room for other programs to run on an average older machine. Unless you're using a expensive top of the line power-house you would never notice these issue and will never understand.

    That's why I keep a decent power house (AMD-64, Quad, 4GB ram) but even that is losing ground when running Vista, Windows-7 32 or 64, with Office-7, Adobe Production, and 6 copies of Opera with many, many windows open in each. One for homework, one for ASM, one for C++, etc.

    I own them all. I do it for testing, but I live by XP. It handles them all better and you can feel it. I keep a few older machines like (P4, 2GB Memory), and if that's not enough for most OS and a few of these programs, out it goes even if it ran great on my power-house. WHY? When I out of town, and can't find a QUANTUM 64, somebody in town got to have at lease a P3 laying around that I can pop my Flash drive to get a simple job done.

    Anyway, about living without tooltips and intellisense, what is so wrong with not wanting to use them after you learn most of what it has to say. I am a not perfect but "very careful" when writing code. After learning C++ the C++ way, you already know I'm going full blast in-line ASM and tooltips or intellisense could ever make since of what I'll be coding and if it could I don't need it making any suggesting that I use xor eax,eax instead of mov eax, 1. Not all C++ programs has it anyway and people been doing fine with-out it to date, I'm sure. As I said, there is nothing like going down to the pits. You quickly learn how to build it back up to the point you need while learning some new tricks along the way. That's when you can say "I know why that happen" and the debugger never had a clue. "ERROR: Unknown." That is not a crime. It can be big FUN, but don't expect no help from the OS or IDE. They might be ......... heehee

  15. #15
    Registered User
    Join Date
    Sep 2010
    Posts
    90
    Header in header

    Tons of info s right here about PCH and everything else it seems. That what I'm taking about ...
    Post number 4 is a great idea to start with.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Can we have vector of vector?
    By ketu1 in forum C++ Programming
    Replies: 24
    Last Post: 01-03-2008, 05:02 AM
  2. Templates and Macros plus more...
    By Monkeymagic in forum C++ Programming
    Replies: 8
    Last Post: 01-20-2007, 05:53 PM
  3. Errors with including winsock 2 lib
    By gamingdl'er in forum C++ Programming
    Replies: 3
    Last Post: 12-05-2005, 08:13 PM
  4. Functions in C
    By shoobsie in forum C Programming
    Replies: 15
    Last Post: 11-17-2005, 01:47 PM
  5. Visual C++ 2005 linking and file sizes
    By Rune Hunter in forum C++ Programming
    Replies: 2
    Last Post: 11-12-2005, 10:41 PM