Join 149,911 C++ Programmers for FREE! Get instant access to thousands of C++ experts, tutorials, code snippets, and more! There are 2,165 people online right now. Registration is fast and FREE... Join Now!
I have a little experience with java, and have been told that now i need to learn C++. So, I download the required compiler, which happens to be DevC++. I even have a Dummies book with example code to help me get started. I copy and paste one of the programs out of the book's included CD, and when I compile it, I get a very strange outcome: The compiler fills up with stuff that I never wrote and sometimes gives me a window talking about something called g++.exe.
I have no idea what's going on, and I know that code is error free, because the same thing happens with any program I enter that is from the Dummies book.
PLEASE HELP ME!!
P.S. I have Windows Vista Enterprise if anyone thinks this has something to do with my problem.
P.S.S I got the same problem when I tried to compile the same programs in the jGRASP compiler.
Sounds like a compiler problem to me. Are you sure that DevC++ comes with a compiler?(I dont know, i use linux) You could try reinstalling it. Otherwhise i would surgest installing MinGW.
If you post your errors it might be easier to figure out the problem.
Dev-C++ does come bundled with a compiler (gcc 3.4.2 under MinGW), so that should be fine - as long as you downloaded the bundle, rather than the exectuable-only option. If there was no compiler included, you wouldn't be getting a lot of errors, just a "could not find executable" error or something like that.
If you can post the code you're trying to compile, as well as the errors that are generated on compilation, we'll probably be able to see what's going on. My guess would be that there's either an error in the code provided with the book, or there are some non-printing characters that are showing up. Please copy and post directly, without any modifications, just so we can see exactly what's going on.
And just so you know, Dev-C++ is an integrated development environment (IDE), not a compiler. The IDE is the program used for editting, formatting, etc. source code, while the compiler is a program that is called to convert the source code into an executable. In this case, your IDE comes bundled with a compiler, but the compiler is still a separate program.
Ok, so first I'll post the code exactly as it appears in the book, and then I'll post what appears in the editing pane once I click the compile button in DevC++.
Conversion.cpp
CODE
// // Program to convert temperature from Celsius degree // units into Fahrenheit degree units: // Fahrenheit = Celsius * (212 - 32)/100 + 32 // #include <cstdio> #include <cstdlib> #include <iostream> using namespace std;
int main(int nNumberofArgs, char* pszArgs[]) {
// enter the temperature in Celsius int celsius; cout << "Enter the temperature in Celsius:"; cin >> celsius;
// calculate conversion factor for Celsius // to Fahrenheit int factor; factor = 212 - 32;
// use conversion factor to convert Celsius // into Fahrenheit values int fahrenheit; fahrenheit = factor * celsius/100 + 32;
// output the results (followed by a NewLine) cout << "Fahrenheit value is:"; cout << fahrenheit << endl;
// wait until user is ready before terminating program // to allow the user to see the program results system("PAUSE"); return 0; }
Okay, now below is what appears in DevC++ once I try to compile it.
CODE
// -*- C++ -*- forwarding header.
// Copyright (C) 1997, 1998, 1999, 2000, 2002 Free Software Foundation, Inc. // // This file is part of the GNU ISO C++ Library. This library is free // software; you can redistribute it and/or modify it under the // terms of the GNU General Public License as published by the // Free Software Foundation; either version 2, or (at your option) // any later version.
// This library is distributed in the hope that it will be useful, // but WITHOUT ANY WARRANTY; without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the // GNU General Public License for more details.
// You should have received a copy of the GNU General Public License along // with this library; see the file COPYING. If not, write to the Free // Software Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, // USA.
// As a special exception, you may use this file as part of a free software // library without restriction. Specifically, if other files instantiate // templates or use macros or inline functions from this file, or you compile // this file and link it with other files to produce an executable, this // file does not by itself cause the resulting executable to be covered by // the GNU General Public License. This exception does not however // invalidate any other reasons why the executable file might be covered by // the GNU General Public License.
// // ISO C++ 14882: 18.1 Types //
/** @file cstddef * This is a Standard C++ Library file. You should @c #include this file * in your programs, rather than any of the "*.h" implementation files. * * This is the C++ version of the Standard C Library header @c stddef.h, * and its contents are (mostly) the same as that header, but are all * contained in the namespace @c std. */
#ifndef _CPP_CSTDDEF #define _CPP_CSTDDEF 1
#pragma GCC system_header
#include <stddef.h>
namespace std { using ::ptrdiff_t; using ::size_t; }
Well, the code should compile just fine - it does for me using both Eclipse and Dev-C++ with gcc 3.4.2 on Windows XP.
That appears to be the cstddef header that has opened itself up in your editting window. You say this occurs when you click the compile button - does anything change when you select compile from the Execute menu? What about compile and run under that same menu?
When you downloaded Dev-C++, did you download the version that comes bundled with the MinGW gcc port? Or just the executable? If you didn't install the version that comes bundled with the MinGW compiler, uninstall, download the bundle, reinstall, and try again. Even if you did install the bundle, I might try a reinstall. There have been a lot of posts concerning Dev-C++ in the last little while, so I'm pretty sure that there are a few bugs in it.
And as a worst case scenario, you may want to try a different IDE and compiler. Dev-C++ has a nice small footprint, but there are others out there that may serve you better. Xing has a tutorial with a listing of free IDEs/compilers in the C++ tutorials section that you may want to check out if it gets to that point.
This post has been edited by jjhaag: 4 Jan, 2008 - 03:04 PM
Ok well it turns out that DevC++ isn't compatible with Vista. It was suggested to me that I download Visual Studio C++ Express, so that is what I did. This application is completely foreign to me, and here comes the dumb question... Once I enter my code into the editing pane, how do I even compile it in this app? Hopefully somebody is familiar with it. Thanks in advance.
I have a little experience with java, and have been told that now i need to learn C++. So, I download the required compiler, which happens to be DevC++. I even have a Dummies book with example code to help me get started. I copy and paste one of the programs out of the book's included CD, and when I compile it, I get a very strange outcome: The compiler fills up with stuff that I never wrote and sometimes gives me a window talking about something called g++.exe.
I have no idea what's going on, and I know that code is error free, because the same thing happens with any program I enter that is from the Dummies book.
PLEASE HELP ME!!
P.S. I have Windows Vista Enterprise if anyone thinks this has something to do with my problem.
P.S.S I got the same problem when I tried to compile the same programs in the jGRASP compiler.
Thanks everyone. The tutorial on Visual C++ Express is quite useful, but I do wonder one thing: Isn't there an easier way to simply start a new.cpp file, write the code, compile it and run it? The tutorial suggests that everytime you have to go to File\New Project, name and save your project, THEN go File\New File, select .cpp file, and save this within the file. I'm used to java IDE where I could just write the code, click compile, click run, and be done with it.
I tried to just go File\New File, select .cpp, but then there is now option to Build, so how would I compile it? Just wondering if there is an easier way, seeing as how Visual C++ Express will likely be used every day by me.