Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Problem Compiling a Program.

jonezi92jonezi92 Member Posts: 224

Hi, im totally new to programming and im learning to use C++ from the Herbert Schildt "A Beginners Guide".

I'm stuck though it seems.... on page freaking 11.  Yes thats right 11.

Its a little project example you can make yourself using Visual Studio's 2010 Express / Borlands C++ Builder.

 

Now... im a little lost because i've Completed the Program, although Debugging is an issue because I'm have alot of trouble Debugging / Compiling the Program.

Steps I've Taken -

1. I've Completed the Program and Saved it under 'Sample.cpp'.

2. I've Executed the "vsvars32" Batch file in The Command Prompt, The Enviroment is now suited for Visual Studio's 2010.(the book im using says i must Execute this file before i can start to compile.)

3. I now Try and enter the Required Commands and it appears that my program isnt an Executable / Recognisable File.

Required Commands comes up as "For Example, to Compile 'Sample.cpp' Using Visual C++ i need to enter -

"C:...>cl -GX Sample.cpp" This is a Command used in Command Prompt so the Selected File is Able to be Compiled.

(when i do this it comes up with 3 Errors, one says i need to use /EHsc instead, which i have tried, same result)

So, i'm Assuming that the three ... is where i need to put the Path Location of my Project at..

 

The Program im trying is -

#include

using namespace std;



// A C++ program begins at main().

int main()

{

   cout << "C++ is power programming.";



   return 0;

}

 

Basically in a Nut shell since my Brain is abit Drained at the moment is that, How do i go about Compiling my Program using Microsoft Visual C++ 2010 Express?

 

I get the Feeling im missing something that is Very Obvious but im just a little puzzled with the software, Please if this doesnt even make sense to you and your a programmer please correct me because im starting to get a little frustrated, Thanks

 

*Edit* - Sorry i dont know if this Applys to these parts of the Forums or not.

Comments

  • FarReachFarReach Member Posts: 229

    You forgot a piece.

    #include

     

    This will allow you to use cout and cin.

    #include is always followed by a reference.

     

     

    Oh, in VC++ you need to:

    #include "stdafx.h"

    If you want to Visual C++ and C++ are slightly different. If you want to learn Visual C++ (Microsoft's edit basically), then get a book on Visual C++. Else, stick with Borland. There are quite a few little quirks in the libraries in Visual Studio, that are different from standard C++ libraries. They will do nothing but cause you a headache, unless you're learning VC++ or know how to change them.

  • jonezi92jonezi92 Member Posts: 224

    Originally posted by FarReach

    You forgot a piece.

    #include

     

    This will allow you to use cout and cin.

    #include is always followed by a reference.

     

     

    Oh, in VC++ you need to:

    #include "stdafx.h"

    If you want to Visual C++ and C++ are slightly different. If you want to learn Visual C++ (Microsoft's edit basically), then get a book on Visual C++. Else, stick with Borland.

    #include <iostream> is actually already in my program i just must of made a typo, but i didnt include stdafx.h  which i will try, i cant seem to find a borland builder download anywhere, could you reccomend a link or site?

  • FarReachFarReach Member Posts: 229

    Originally posted by jonezi92

    Originally posted by FarReach

    You forgot a piece.

    #include

     

    This will allow you to use cout and cin.

    #include is always followed by a reference.

     

     

    Oh, in VC++ you need to:

    #include "stdafx.h"

    If you want to Visual C++ and C++ are slightly different. If you want to learn Visual C++ (Microsoft's edit basically), then get a book on Visual C++. Else, stick with Borland.

    #include is actually already in my program i just must of made a typo, but i didnt include stdafx.h  which i will try, i cant seem to find a borland builder download anywhere, could you reccomend a link or site?

    I don't believe Borland is developed anymore. Use Dev C++, which isn't being developed any more either, but I still believe it works.

     

    Edit:

    http://info.borland.com/devsupport/borlandcpp/

    I still suggest Dev C++. Look at the bottom of that page. 

    Last Modified Wednesday, 13-Mar-2002 11:50:04 EST

    I know Dev C++ continued development until at least 2005. But, if you insist on using Borland, you can use the Y2K update. lol

     

    Edit2:

    I just re-read your original post. Throw that book away and find a better one. 

  • jonezi92jonezi92 Member Posts: 224

    Originally posted by FarReach

    Originally posted by jonezi92


    Originally posted by FarReach

    You forgot a piece.

    #include

     

    This will allow you to use cout and cin.

    #include is always followed by a reference.

     

     

    Oh, in VC++ you need to:

    #include "stdafx.h"

    If you want to Visual C++ and C++ are slightly different. If you want to learn Visual C++ (Microsoft's edit basically), then get a book on Visual C++. Else, stick with Borland.

    #include is actually already in my program i just must of made a typo, but i didnt include stdafx.h  which i will try, i cant seem to find a borland builder download anywhere, could you reccomend a link or site?

    I don't believe Borland is developed anymore. Use Dev C++, which isn't being developed any more either, but I still believe it works.

     

    Edit:

    http://info.borland.com/devsupport/borlandcpp/

    I still suggest Dev C++. Look at the bottom of that page. 

    Last Modified Wednesday, 13-Mar-2002 11:50:04 EST

    I know Dev C++ continued development until at least 2005. But, if you insist on using Borland, you can use the Y2K update. lol

     

    Edit2:

    I just re-read your original post. Throw that book away and find a better one. 

    I dont think the Book is the problem, its just trying to work out The Command Line "cl" to actually Compile my Program itself,

    The book so far has been great, im just having a little trouble trying to work around microsoft visual 2010,

    The info i find on it isnt really helpful at all, even the 2008 version has a easy "Compile" button to press and im going to think it just does it for you,

    but the 2010 version doesnt have that at all, i dont see how this would make sense

     

    *Edit* - in the 2010 you have to manually Activate vsvars32 (not sure in 2008) in the command prompt and then execute your program which it doesnt even recognise as a file

  • jonezi92jonezi92 Member Posts: 224

    So insted of using microsoft visual c++ i need to use Dev C++ for just "C++" ?

     

    since microsoft visual is a slightly edited version of C++...  that aint going to work with this book..

     

    do you know if DEV C++ is compatable with windows 7 at all??

  • FarReachFarReach Member Posts: 229

    Originally posted by jonezi92

    So insted of using microsoft visual c++ i need to use Dev C++ for just "C++" ?

     

    since microsoft visual is a slightly edited version of C++...  that aint going to work with this book..

     

    do you know if DEV C++ is compatable with windows 7 at all??

    Idk, haven't used it since XP. Try it and see. It's only 13mb and free.

    http://www.bloodshed.net/devcpp.html

    Don't get caught up on my words btw, there's a little bit more to it than that, but you'll understand later. C++ is still C++.

  • MaltorrMaltorr Member UncommonPosts: 1

    To compile within Microsoft Visual C++ 2010 Express:

    1. Create a New Project

    2. Create a New Source

    Right click Source File --> Add --> New Item

    Select C++ File(.cpp)

    3. Enter the source code you had above.

    #include <iostream>

    using namespace std;

    // A C++ program begins at main().

    int main()

    {

    cout << "C++ is power programming.";

    return 0;

    }

    4. Right click the project name under Solution Explorer and select Build

    5. Select Start Debugging

     

  • ZyonneZyonne Member Posts: 259

    You could always get MinGW or Cygwin and use the GCC compiler g++. I don't program C++, but I tested compiling your sample code with g++, and it works fine (with the native linux compiler, but should be the same with Cygwin or MinGW).

  • jonezi92jonezi92 Member Posts: 224

    Originally posted by Maltorr

    To compile within Microsoft Visual C++ 2010 Express:

    1. Create a New Project

    2. Create a New Source

    Right click Source File --> Add --> New Item

    Select C++ File(.cpp)

    3. Enter the source code you had above.

    #include

    using namespace std;

    // A C++ program begins at main().

    int main()

    {

    cout << "C++ is power programming.";

    return 0;

    }

    4. Right click the project name under Solution Explorer and select Build

    5. Select Start Debugging

     

    Where can i find the "Solution Explorer" .... or is it just Build Solution?

  • jonezi92jonezi92 Member Posts: 224

    Originally posted by Zyonne

    You could always get MinGW or Cygwin and use the GCC compiler g++. I don't program C++, but I tested compiling your sample code with g++, and it works fine (with the native linux compiler, but should be the same with Cygwin or MinGW).

    in this book it says i can run / compile programs using the latest microsoft visual c++, clearly i have something wrong.

     

    Im trying Cygwin now to see if i can actually use it with this book, thanks

  • jonezi92jonezi92 Member Posts: 224

    Originally posted by Maltorr

    To compile within Microsoft Visual C++ 2010 Express:

    1. Create a New Project

    2. Create a New Source

    Right click Source File --> Add --> New Item

    Select C++ File(.cpp)

    3. Enter the source code you had above.

    #include

    using namespace std;

    // A C++ program begins at main().

    int main()

    {

    cout << "C++ is power programming.";

    return 0;

    }

    4. Right click the project name under Solution Explorer and select Build

    5. Select Start Debugging

     

    Done all of that, When debugging i get -

     error C2857: '#include' statement specified with the /YcStdAfx.h command-line option was not found in the source file

    ========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========

    the project is being created under "Win32 Console Application" if that has anything to do with it

     

  • ZyonneZyonne Member Posts: 259

    Originally posted by jonezi92

     error C2857: '#include' statement specified with the /YcStdAfx.h command-line option was not found in the source file

    ========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========

    the project is being created under "Win32 Console Application" if that has anything to do with it

     

    It's been ages since I've used Visual Studio, or C++ so I may be way off here, but it seems like pre-compiled headers (setting somewhere?) are messing up your build. Try adding:

    #include <cstdlib> 



    or 

    #include <cstdio>

    It shouldn't be necessary when including <iostream>, but worth a shot.

     

     

     

     

     

     


  • jonezi92jonezi92 Member Posts: 224

    Originally posted by Zyonne

    Originally posted by jonezi92


     error C2857: '#include' statement specified with the /YcStdAfx.h command-line option was not found in the source file

    ========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========

    the project is being created under "Win32 Console Application" if that has anything to do with it

     

    It's been ages since I've used Visual Studio, or C++ so I may be way off here, but it seems like pre-compiled headers (setting somewhere?) are messing up your build. Try adding:

    #include  

    or 

    #include

    It shouldn't be necessary when including , but worth a shot.

     

     

     

     

     

     

    I've managed to fix one problem, i got into the Solution Explorer - C/C++ and then in the Precompiled Headers, you can actually change the settings to not use them at all, which fixed the problem i was having,

    but it just lead to another problem which just p'd me off, so now im using DEV C++, which straight away, worked first time building, debugging, compiling and then running,

    Hopefully! i could use this DEV C++ throughout this book now but im still not totally sure.

     

    Like previously mentioned, Visual C++ is a slightly edited C++ language by microsoft that uses a differant library? thats probobly the problem why i was having Error after Error, unfortunately im not learning with the Visual C++, im just using the original 3rd revision of C++ is it?

  • ZyonneZyonne Member Posts: 259

    Dev C++ is a front.-end to an outdated version of MinGW which has (obviously outdated) windows ports of the GCC compiler suite. It's probably possible to get Dev C++ to work with an updated version of MinGW, but that's not likely to be worth the effort unless most of the code examples won't work at all. Anyway, if you want to learn Visual C++, you should keep tinkering with that until it works. If you want to learn C++ in general, GCC is much more standardized, and you'll learn quite a bit from figuring out the differences when something won't compile.

  • jonezi92jonezi92 Member Posts: 224

    Originally posted by Zyonne

    Dev C++ is a front.-end to an outdated version of MinGW which has (obviously outdated) windows ports of the GCC compiler suite. It's probably possible to get Dev C++ to work with an updated version of MinGW, but that's not likely to be worth the effort unless most of the code examples won't work at all. Anyway, if you want to learn Visual C++, you should keep tinkering with that until it works. If you want to learn C++ in general, GCC is much more standardized, and you'll learn quite a bit from figuring out the differences when something won't compile.

    Dev C++ works completely on its own at the moment, the latest version to use MinGW / Cygwin as of yet, but i only did a simple source code.

    i only want to learn the General C++, hopefully then leading onto more advanced C++ such as beginners Game Development and so on.

    what is GCC by the way? like i said im still new to all of this :)

  • FarReachFarReach Member Posts: 229

    Originally posted by jonezi92

    Originally posted by Zyonne

    Dev C++ is a front.-end to an outdated version of MinGW which has (obviously outdated) windows ports of the GCC compiler suite. It's probably possible to get Dev C++ to work with an updated version of MinGW, but that's not likely to be worth the effort unless most of the code examples won't work at all. Anyway, if you want to learn Visual C++, you should keep tinkering with that until it works. If you want to learn C++ in general, GCC is much more standardized, and you'll learn quite a bit from figuring out the differences when something won't compile.

    Dev C++ works completely on its own at the moment, the latest version to use MinGW / Cygwin as of yet, but i only did a simple source code.

    i only want to learn the General C++, hopefully then leading onto more advanced C++ such as beginners Game Development and so on.

    what is GCC by the way? like i said im still new to all of this :)

    GNU Compiler, generally used in linux systems. 

    I wouldn't worry too much about getting MinGW/Cygwin. Just stick with Dev C++ and learn, because you have a long long way to go still. :-)

    Good Luck

  • ShinamiShinami Member UncommonPosts: 825

    I use microsoft visual studio C++. I've ran into problems using Bloodshed C++ and worked for very simple programs but had linking problems with advanced and larger programs.

     

    The major problem to C++ is the following:

     

    The C++ library has a Standard Library. Up to this point there are no major problems. The major problem starts when C++ compilers have both, the Standard Library and Non-Standard Library. It means depending on the compiler you have to actually code things differently. C++ became a Class Based, Object Oriented Language in the 80s where previous versions were classical programming and many things were deprecated in the language through revisions.

     

    Microsoft Visual Studio is one of the programs that has a more complete C++ library and conforms to more standards (and yes, I hate complimenting microsoft programs since most suck) and I tend to put that on every windows machine, but alas, complications do arise from time to time.

     

    If you want to work with C++ a lot, it really is good to set up a Linux Platform and learn how to write C programs and then C++ programs.

     

    As a game programmer and OS programmer, C++ offers the strength of being able to have direct access to memory through pointers. It is also one of the fastest high level programming languages and by far one of the few languages which allow you to insert Assembly Programming directly into the language. Due to this, C++ is great for creating drivers, Game Engines and Games in General. Its main weakness is a divergence from standards forcing people to have multiple compilers to compile a program and even Operating Systems.

     

    All in all, I've had a lot of fun with the Language. My favorite Programming Language is actually Java Programming.

     

    I like helping out, but I don't use Online Forumboards to help people with Homework Assignments. If you wish to learn programming, go registrer to a Programming Forumboard where its central topic is Programming Languages and Design.

  • jonezi92jonezi92 Member Posts: 224

    Originally posted by FarReach

    Originally posted by jonezi92


    Originally posted by Zyonne

    Dev C++ is a front.-end to an outdated version of MinGW which has (obviously outdated) windows ports of the GCC compiler suite. It's probably possible to get Dev C++ to work with an updated version of MinGW, but that's not likely to be worth the effort unless most of the code examples won't work at all. Anyway, if you want to learn Visual C++, you should keep tinkering with that until it works. If you want to learn C++ in general, GCC is much more standardized, and you'll learn quite a bit from figuring out the differences when something won't compile.

    Dev C++ works completely on its own at the moment, the latest version to use MinGW / Cygwin as of yet, but i only did a simple source code.

    i only want to learn the General C++, hopefully then leading onto more advanced C++ such as beginners Game Development and so on.

    what is GCC by the way? like i said im still new to all of this :)

    GNU Compiler, generally used in linux systems. 

    I wouldn't worry too much about getting MinGW/Cygwin. Just stick with Dev C++ and learn, because you have a long long way to go still. :-)

    Good Luck

    Yeh Dev C++ seems to provide what i need at the moment and thats great,

    I remember see'ing a "Developers Corner" at one point in the forum boards if im right, what ever happend to that section in the forums?

  • nestor28nestor28 Member Posts: 1

    Where can i find the "Solution Explorer" .... or is it just Build Solution?

Sign In or Register to comment.