-
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.
-
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
-
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.
-
Oh, I see. You might want to place the file in a project, or 'Solution'.
File -> New -> Project
then
Visual C++ -> General -> Empty Project
-
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?
-
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.
-
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;
}
-
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.
-
Show your source file for one. I just did what you said and my example code compiled just fine.
-
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 ==========
-
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. :/
-
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.
-
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? :D
-
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.
-
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]
-
>>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.
That didn't work for me. I use pragmas to disable those warnings
#pragma warning(disable: 4996)
-
Code:
#include <stdlib.h>
#include <time.h>
Don't know if it will help, but those should be:
Code:
#include <cstdlib>
#include <ctime>
-
>>Make sure you define CRT_SECURE_NO_DEPRECATE
>>That didn't work for me
That's because its supposed to be _CRT_SECURE_NO_DEPRECATE
Works fine then.