Slight problem "n00b"

Apr 18, 2012 at 8:35pm
Hi guys im just playing about, now heres my code


// operating with variables
#include "stdafx.h"
#include <iostream>
using namespace std;

int main ()
{
// declaring variables:
int a, b, c, d;
int result;

// process:
a = 20;
b = 30;
c = 10;
d = 5;
a = a + 1;
result = a + b + c + d;

// print out the result:
cout << result;
cin.get() ;
// terminate the program:
return 0;

}



Personally i cant see anything wrong with this, and the console closes down fine ect, when i either enter a charecter or click the "x"

But afterwards i get this compile error 1>------ Build started: Project: Project1, Configuration: Debug Win32 ------
1> Project1.cpp
1>LINK : fatal error LNK1168: cannot open C:\Users\James\documents\visual studio 2010\Projects\Project1\Debug\Project1.exe for writing
========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========


which to me means the console hasnt closed down properly, but its not on my task manager as still running, and its getting quite annoying as i have to reboot my PC everytime i want to re-compile. Is this a issue with my code, my computer being stupid?

Apr 18, 2012 at 8:38pm
You say you get this error AFTER you run the program?

If you change the program to print out some text before exiting, does it show that text when you run it? (Testing if it runs an old version or the new one)
Apr 18, 2012 at 8:40pm
Yeh i compile my program, run the program.

Change my code a little bit go to compile again and get that error

(from my own common sense) i think it means the program didnt shut down properly so visual cant re-pack the .exe, But i dont know why it didnt close down properly....


edit- it runs on the old version (as in the version i first compiled).. if that makes sense?
Last edited on Apr 18, 2012 at 8:41pm
Apr 18, 2012 at 8:44pm
How do you run the program after you build it?
Apr 18, 2012 at 8:49pm
Doube click project1.exe in C:\Users\James\documents\visual studio 2010\Projects\Project1

it opens the console up, displays the awnser, and i press a key it closes down.

Then obviously i go back in visual studio edit some variables, create some new ones try to compile again and get that error.



Apr 18, 2012 at 8:54pm
I think it may be Windows struggling to find an icon in your program (obviously there isn't one so it can't).

When you go to that folder, Windows tries to load the icon for it and gets stuck...forever. (hence the restart factor)

To fix it, just use the green play button to run the program from VC++ itself. You will still have to restart your computer even if you just open the folder with the EXE in it.


I'd recommend reinstalling VC++, because it *should* have a default icon.
Last edited on Apr 18, 2012 at 8:55pm
Apr 18, 2012 at 9:12pm
Thanks for your help.

Tried the green play button and still get the same problem.
Think im going to have to do a complete un-install and re-install only problem is looking on google its a right bugger to unistall lol.

Yay! thanks for your time LB
Topic archived. No new replies allowed.