Thread: Visual C++

  1. #1
    Registered User
    Join Date
    Apr 2006
    Posts
    132

    Visual C++

    I have Visual C++ 2005 express edition but it wont compile or run anything.

    I have just wrote a Slot Machin program but how do i get it to go?

    i just choose NEW -> File -> Visual C++ -> .CPP and click OK.

    write the code, save as and name it and save to desktop. then what? there is no Compile or Run or anything? im confused as hell, with Dev C++ u just hit Compiler and Run.

    Anyone know what im doing wrong? this is my first program and i cant even test it out lmao.

    please help. cheers.

  2. #2
    C++ Witch laserlight's Avatar
    Join Date
    Oct 2003
    Location
    Singapore
    Posts
    28,413
    If you want to compile and link:
    Build -> Build Solution

    If you want to compile and link from scratch:
    Build -> Rebuild Solution

    If you just want to compile:
    Build -> Compile

    To run from within the IDE:
    Debug -> Start Without Debugging
    Quote Originally Posted by Bjarne Stroustrup (2000-10-14)
    I get maybe two dozen requests for help with some sort of programming or design problem every day. Most have more sense than to send me hundreds of lines of code. If they do, I ask them to find the smallest example that exhibits the problem and send me that. Mostly, they then find the error themselves. "Finding the smallest program that demonstrates the error" is a powerful debugging tool.
    Look up a C++ Reference and learn How To Ask Questions The Smart Way

  3. #3
    Registered User
    Join Date
    Apr 2006
    Posts
    132
    Thats the thing, there is NO Build. and in Debug the start without debug is dark grey and i cannot choose it. i cannot work it out. when i choose file -> NEW do i choose project or just file and then .CPP? or what?

    EDIT! found the Build but the button is dark grey and cannot choose it.

  4. #4
    C++ Witch laserlight's Avatar
    Join Date
    Oct 2003
    Location
    Singapore
    Posts
    28,413
    Oh, I see. You might want to place the file in a project, or 'Solution'.

    File -> New -> Project
    then
    Visual C++ -> General -> Empty Project
    Quote Originally Posted by Bjarne Stroustrup (2000-10-14)
    I get maybe two dozen requests for help with some sort of programming or design problem every day. Most have more sense than to send me hundreds of lines of code. If they do, I ask them to find the smallest example that exhibits the problem and send me that. Mostly, they then find the error themselves. "Finding the smallest program that demonstrates the error" is a powerful debugging tool.
    Look up a C++ Reference and learn How To Ask Questions The Smart Way

  5. #5
    Registered User
    Join Date
    Apr 2006
    Posts
    132
    thanks that worked. but it says ..

    slot.cpp
    .\slot.cpp(2) : fatal error C1083: Cannot open include file: 'iostream.h': No such file or directory
    Build log was saved at "file://c:\Documents and Settings\Reece.LAPTOP\My Documents\Visual Studio 2005\Projects\slot\slot\Debug\BuildLog.htm"
    slot - 1 error(s), 0 warning(s)

    how come this dont have iostream?

    EDIT! i downloaded iostream and placed it in include. now it says TOO MANY INCLUDE FILES.. wtf. i thought you can use as many as u want?
    Last edited by Hugo716; 05-23-2006 at 11:23 PM.

  6. #6
    Registered User VirtualAce's Avatar
    Join Date
    Aug 2001
    Posts
    9,607
    It does. Check your include directories in your project options.

    Also make sure you read the information related to developing Windows apps inside of 2005 express. There are specific instructions that if not followed will result in Windows API code not executing at all.

    I would NOT recommend creating a 2005 project by simply finding your 2003 or MSVC 6 project file and letting 2005 convert it. Yes it works, but the build will NOT work. For some reason it still attempts to access MSVCRT.DLL which 2005 does not use. MSVC 2005 uses VC80.dll and is linked in dynamically. If you get an error that states the application configuration is incorrect, your System Admin->Event log viewer will tell you that MSVC 2005 is the source. It is simply telling you in Windows speak that it cannot find VC80.dll.
    You should look in the help file about private and mixed assemblies as well as about manifests.

    The BEST way to create a project from existing code is to use Project->From existing code.
    This will allow you to setup your project using your old source files, but MSVC 2005 will place the correct references in the build so it now links with VC80.dll and does not attempt to link with MSVCRT.dll.

    The other way is to create a new 2005 project and then add in your old source files as you see fit. Note that you will probably get about a million warnings and errors because things have changed a lot in 2005. Make sure you define CRT_SECURE_NO_DEPRECATE in the Project->Properties->C/C++->Preprocessor->Preprocessor definitions field. Otherwise the compiler will flag every reference to a C standard library function as deprecated.

    If you have more questions I'll be glad to answer them.

  7. #7
    Sweet
    Join Date
    Aug 2002
    Location
    Tucson, Arizona
    Posts
    1,820
    I am guessing VC++ doesn't support iostream.h anymore try just iostream since it is the standard header now. The put everything in the std namespace
    Example:
    Easy Way
    Code:
    #include <iostream>
    using namespace std;
    
    int main()
    {
        cout<<"Hello VC++";
        return 0;
    }
    or a more prefered way
    Code:
    #include <iostream>
    
    int main()
    {
        std::cout<<"Hello VC++";
        return 0;
    }
    Woop?

  8. #8
    Registered User
    Join Date
    Apr 2006
    Posts
    132
    im confused big time now lol.

    I went to FIle -> NEW -> PROJECT -> VC++ General -> Empty project

    I then added a new source file and wrote the code i wanted to do. i hit Build and it says too many header files being used. how can i fix this? im not using any old stuff or whatever. i just installed express 2005 tonight and im trying my first program.

  9. #9
    Sweet
    Join Date
    Aug 2002
    Location
    Tucson, Arizona
    Posts
    1,820
    Show your source file for one. I just did what you said and my example code compiled just fine.
    Woop?

  10. #10
    Registered User
    Join Date
    Apr 2006
    Posts
    132
    code is

    Code:
    // Slot Machine Game - Tester 
    #include <iostream>
    #include <stdlib.h>
    #include <time.h>
    using namespace std;
    int main()
    {
    	
    	int z, 1, 2, 3, tokens=6;
    	srand(time(0));
    	
    	cout<<"\t  Welcome to slots\n"
    		<<"\t Type 1 to play, 2 not to play\n";
    
    	cin>>z;
    		while(tokens!=0)
    	{
    		cout<<"You have "<<token<< " tokens Left\n\n"
    	    <<"Pull Lever? (1 to pull, 2 not to pull)\n\n";
    	cin>>z;
    	
    	
    	
    	
    	if(z==1)
    {	
    	
    	 1 = 1+rand() %10;
    	 2 = 1+rand() %10;
    	 3 = 1+rand() %10;
    	
    	cout<<"\t\t"<<1<<"          "<<2<<"          "<<3<<"\n\n";
    	
    }
    		else
    		cout<<"OK!!!\n";
    		{		
    				
    		if(1==2==3)
    		{
    			
    			tokens+=2;
    			cout<<"Congrats, You win\n\n";
    		}		
    		if(1==2 || 2==3 || 1==3)
    		{
    			tokens+=1;
    		
    		cout<<"You got ttwo out of three\n\n";
    		
    		
    		}
    		else
    		{
    			tokens-=1;
    			
    		
    		cout<<"Better luck next time! You loose!\n\n";
    		}
    		
    		}
    
    		
    		}
    			system("PAUSE");	
    			return 0;
    	
    }
    getting big error
    Code:
    ------ Build started: Project: slot, Configuration: Debug Win32 ------
    Compiling...
    slot.cpp
    .\slot.cpp(9) : error C2059: syntax error : 'constant'
    .\slot.cpp(18) : error C2065: 'tokens' : undeclared identifier
    .\slot.cpp(18) : fatal error C1903: unable to recover from previous error(s); stopping compilation
    Build log was saved at "file://c:\Documents and Settings\Reece.LAPTOP\My Documents\Visual Studio 2005\Projects\slot\slot\Debug\BuildLog.htm"
    slot - 3 error(s), 0 warning(s)
    ========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========
    Last edited by Hugo716; 05-23-2006 at 11:58 PM.

  11. #11
    Registered User
    Join Date
    Apr 2006
    Posts
    132
    ahh thing i sussed one.

    i called it tokens, but i bet tokens means something else. am i right?
    i should make it token not tokens?

    EDIT! Or not. :/

  12. #12
    Sweet
    Join Date
    Aug 2002
    Location
    Tucson, Arizona
    Posts
    1,820
    You can't use actual values like 1, 2, 3 for variable names. Try one, two, three for the names or even better use more descriptive names. That program looks like it could use some redoing so maybe take a look at the tutorials on this site and try it agian.
    Woop?

  13. #13
    Registered User
    Join Date
    Apr 2006
    Posts
    132
    done it. thanks. i changed the 1, 2 and 3 to a b and c. worked fine that time.

    what do u mean needs re doing, what is wrong with it?

  14. #14
    The superhaterodyne twomers's Avatar
    Join Date
    Dec 2005
    Location
    Ireland
    Posts
    2,273
    If you right click on one of the menu bars, and click "Customize ... ", I'm sure there's a way to make a build/compile/debug toolbar, or shortcut.

  15. #15
    The Richness... Richie T's Avatar
    Join Date
    Jan 2006
    Location
    Ireland
    Posts
    469
    Or do as I do - hit F7 to build solution, and ctrl+F5 to run the
    release build which will give you the lovely "Press Enter to
    continue..." at the end - hitting F5 on its own runs the debug
    build which is for diagnosing problems and doesn't feature that
    little pause.

    [edit]
    I changed all the 1,2,3 to a,b,c and the program runs - looping
    infinitely though - your while loop condition (tokens != 0) never
    becomes true
    [/edit]
    Last edited by Richie T; 05-24-2006 at 02:34 AM.
    No No's:
    fflush (stdin); gets (); void main ();


    Goodies:
    Example of fgets (); The FAQ, C/C++ Reference


    My Gear:
    OS - Windows XP
    IDE - MS Visual C++ 2008 Express Edition


    ASCII stupid question, get a stupid ANSI

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. We Got _DEBUG Errors
    By Tonto in forum Windows Programming
    Replies: 5
    Last Post: 12-22-2006, 05:45 PM
  2. C++ std routines
    By siavoshkc in forum C++ Programming
    Replies: 33
    Last Post: 07-28-2006, 12:13 AM
  3. load gif into program
    By willc0de4food in forum Windows Programming
    Replies: 14
    Last Post: 01-11-2006, 10:43 AM
  4. Errors with including winsock 2 lib
    By gamingdl'er in forum C++ Programming
    Replies: 3
    Last Post: 12-05-2005, 08:13 PM
  5. Learning OpenGL
    By HQSneaker in forum C++ Programming
    Replies: 7
    Last Post: 08-06-2004, 08:57 AM