Hi there, I am new to C++ and trying to get my head around it. I am writing really simple and small programs and I have Visual C++. Now, can anybody summarize how I can run a program I wrote with C++ on Visual? The guide that comes with the product doesn't seem to be that helpful, so I was just wondering if you guys can help me/telling me where to find a simple guide on how to run my own programs.
Thanks

You should be able to open any standard *.cpp and *.h files without any special steps. What exactly is the issue you are having?

Are you trying to open the sources in VC++ and can't? Or are you trying to compile them after writing them for a different compiler and are getting errors?

Each IDE has its own version of a project system and the files that support it are mostly IDE specific, so you may need to create a new VC++ project to add your existing files to, but the sources should be openable without much, if any, messing around... Keeping that in mind, what are your current compiler and IDE?

Edited 6 Years Ago by Fbody: n/a

Hi there,
basically the issue was that I couldn't work out how to use Visual C++ (I have got version 6.0). I managed to find some short tutorial, but still can't get my head around that. I was trying to compile a simple program (which I uploaded as an attachment) I found on my manual, but I am not sure how to do it.
I have selected File, New, Win32 Application, gave the project a name (Example 1), then selected "a typical Hello World! application", finish and Ok. Then with the new project open, I go File, New, and choose C++ source file, give it file name "Example final", select a location and ok. The, when I paste the code attached, I click F7 to compile and I got the following error:
--------------------Configuration: Example 1 - Win32 Debug--------------------
Compiling resources...
Compiling...
StdAfx.cpp
Compiling...
Example 1.cpp
Example final.cpp
c:\documents and settings\antobbo_2\desktop\example\example 1\example final.cpp(28) : fatal error C1010: unexpected end of file while looking for precompiled header directive
Generating Code...
Error executing cl.exe.

Example 1.exe - 1 error(s), 0 warning(s)

Sorry, I am sure it will be a really silly mistake!
Thanks

Attachments
/* My first C++ program
by Antonio Borrillo on 12/01/10. */

#include <iostream>

int main()

{

int number1;
int number2;
int sum; // variable declarations //

std::cout <<"Enter the first integer";
std::cin >> number1;

std::cout <<"Enter the second integer";
std::cin >>number2;

sum = number1 + number2;

std::cout << "Sum is" << sum << std::endl;

return 0;

}

No, it's not your mistake. The pre-compiled headers system can be a royal pain. Unfortunately, I can't help you fix that, I haven't dealt with the issue often enough myself.

I think you just need to exclude the project files "stdafx.h" and "stdafx.cpp" to get around it.

Hopefully someone else can help you.

Hi there, I am new to C++ and trying to get my head around it. I am writing really simple and small programs and I have Visual C++. Now, can anybody summarize how I can run a program I wrote with C++ on Visual? The guide that comes with the product doesn't seem to be that helpful, so I was just wondering if you guys can help me/telling me where to find a simple guide on how to run my own programs.
Thanks

Open Visual C++
goto File > New > Project...
select win32 Console app
name it
click next
now it'll give you a project settings page...
check 'Empty Project' and uncheck 'Precompiled Headers'
click Finish

ok...now goto Project > add new item
select .cpp file, name it, and make it
paste code in, and press F7 to build your code. Press shift+F5 to run your program.

Just include the precompiled header (stdafx.h) in all the source files before including any other headers.

The precompiled header option can come very handy if you've a boatload of headers that you aren't going to change, so that it won't need to be built with every compilation!

Edited 6 Years Ago by Rajesh R Subram: n/a

thanks everybody guys, for now I followed Athlon32's suggestion and, even if I can't see the Empty Project and Precompiled Headers radio button I managed to compile and execute the program. I will need to do some readings about Visual C++ as soon as I can, but I was mainly interested in getting my program run. I will probably post again here, because I am still at the beginning!!
Thanks again

This article has been dead for over six months. Start a new discussion instead.