Best free C++ compiler that runs on windows

Macha

King
Joined
Dec 8, 2006
Messages
859
Location
Ireland
I'm starting to learn c++ and am just wondering where to get a good compiler that runs on windows (I have gcc as part of my linux install but I have no internet and a full partition on linux) . I got a few books from my local library but they are usually a good few years old and give names of websites that don't exist anymore or have broken/missing discs.
 
gcc works quite well with cygwin.
I prefer MinGW, though, since it is easier to integrate into IDEs. Both DevCpp and Code::Blocks ship with it, afaik.
 
Yeah, DevCpp is what I used when I was teaching myself. It's about as plug and play as you can get.
 
Visual Studio is just about the best IDE out there for windows. The express version is somewhat limited though, I just can't remember by how much (only thing I remember for sure is that it doesn't include MFC). If you're a student though the academic version can be had for $50 - worth every penny IMO if you're even semi-serious about windows programming.
 
VS might be best IDE, but doing C++ development with MS C/C++ compiler isn't best you can do.

Eclipse isn't any worse, and it is free, and compiler (gcc) is free as well. Gcc is widely used.
 
Visual Studio is just about the best IDE out there for windows. The express version is somewhat limited though, I just can't remember by how much (only thing I remember for sure is that it doesn't include MFC).
In my opinion that's a good thing ;) (I think it's the worst GUI toolkit I've ever come across, and thankfully Microsoft have moved onto .NET, so wouldn't recommend anyone learning it now.)

Wikipedia lists the limitations: http://en.wikipedia.org/wiki/Microsoft_Visual_Studio_Express . I'm not sure there's anything significant for most people - the Express version is good enough for major real world projects, and certainly does well for someone just learning C++.

If you're a student though the academic version can be had for $50 - worth every penny IMO if you're even semi-serious about windows programming.
Well, he can always upgrade later if he need a feature that isn't in the Express version. But either way, I agree that Visual Studio is very good (and much better than the earlier versions a few years ago).
 
Ok. I have my compiler and everything set up. Does anyone know how to check if an input is a float (and not a string like n)?

EDIT: Does anyone know how to get it to output large floats normally instead of scientific notation

e.g
10,488,000,000 * 0.35 is displayed as 3.67080e+09 when I want 3670800000.
 
If you are using a basic input stream like istream (via the cin object), then you can't. As far as the stream is concerned, the input is no more than an array of characters and it is up to you to specify another type.

It is possible to bootstrap a basic run time type information system by including a type identifier for each input value. You'd then have to check for the identifier in your programme and cast the input (exluding the ID, of course) to the correct type.

As for the second question:

Use printf with with %f instead of %e.
float output = 10488000000 * 0.35;
printf("Value: %f", output);
 
Visual Studio is just about the best IDE out there for windows. The express version is somewhat limited though, I just can't remember by how much (only thing I remember for sure is that it doesn't include MFC). If you're a student though the academic version can be had for $50 - worth every penny IMO if you're even semi-serious about windows programming.

If you're a student, you can get Visual Studio Pro for free: https://downloads.channel8.msdn.com/
 
Visual Studio is great but i wouldn't pay for it unless the recent versions are an absolute relevation (i'm using VS2005).
VS2005 has only one feature that i find hard to replace with free solutions iand that s the incorporated resource editor.
 
If you are using a basic input stream like istream (via the cin object), then you can't. As far as the stream is concerned, the input is no more than an array of characters and it is up to you to specify another type.

It is possible to bootstrap a basic run time type information system by including a type identifier for each input value. You'd then have to check for the identifier in your programme and cast the input (exluding the ID, of course) to the correct type.

As for the second question:

Use printf with with %f instead of %e.
float output = 10488000000 * 0.35;
printf("Value: %f", output);

Thanks.

Is there any other ways to get command line input other than cin that do allow you to check the type?
 
Ok. I have my compiler and everything set up. Does anyone know how to check if an input is a float (and not a string like n)?

If you're unsure of the type you'll need to take the input as a string and check it yourself, then convert it using the atoi/atof functions (though in something that was seriously using it I'd probably use boost::lexical_cast instead)

Something like:

Code:
#include <iostream>
#include <cstdlib>
#include <string>

using namespace std;

int main(int argc, char** argv)
{
  string input;
  int iValue;
  double fpValue;
  
  cout << "Enter a number: ";
  cin >> input;
  
  if (input.find('.') != string::npos)
  {
    fpValue = atof(input.c_str( ));
    cout << "You entered a floating point number, " << fpValue << endl;
  }
  else
  {
    iValue = atoi(input.c_str( ));
    cout << "You entered an integer, " << iValue << endl;
  }
  
  return 0;
}

EDIT: Does anyone know how to get it to output large floats normally instead of scientific notation

Use-
cout.setf(ios::fixed);

Though as Till said the printf family of functions are 100x easier to use if you're doing a lot of formatted output.

Is there any other ways to get command line input other than cin that do allow you to check the type?

All input from the console is the same type- char, a sequence of characters. All that happens when you use the extraction operator (>>) is that those characters are automatically interpreted to be a number or whatever else.
 
Thanks.

Is there any other ways to get command line input other than cin that do allow you to check the type?

Not without adjusting the input. You have to identify the type as you make your input. For example by using the first character of each input array to store an type ID.
The following is a quick and (very) dirty hack to show the principle:

Example input:
"1Blabla" //1 signifies a character array
"2666" //2 signifies an integer

Code:
#include <iostream>
#include <cstdlib>

int main (int arg, char* args)
{
	char* input = new char[256];
	std::cin.width(256);
	printf("Enter input. Preceed cstring with 1, integer with 2\n");
	std::cin >> input;
	//convert first character to an int. Must be ASCII
	int type = static_cast<int>(input[0]) -48;

	switch(type)
	{
		//one case for each type you want to use

		//input is a character array. No casting needed
		case 1:
			input++;
			printf("Char*: %s\n",input);
			break;
		//2 stands for integer
		case 2:
			input++;
			int output = atoi(const_cast<const char*>(input));
			printf("Int %d\n", output);
			break;
		//...
	}
	input--;
	delete[] input;
	input = NULL;
	return 0;
}

Edit: Crosspost with Speedo.
 
Final problem. My program is taking inputs and at the end when performing a sum on the inputs, it gets it wrong.

e.g

Code:
float answer = num_to_divide * (current_percentage / 100);
if num_to_divide is 100 and current_percentage is 59, answer gets assigned to 58.999996 .
 
Floating point (decimal) numbers can't be precisely represented on a computer, because the computer has to use binary to represent them. You'll get some small errors like that.
 
Back
Top Bottom