-
exe size
i did this test program and compiled it...but why da hell do it make an exe with about 500kb!??!
PHP Code:
// test1.cpp : Defines the entry point for the console application.
//
#include "stdafx.h"
#include <iostream>
using namespace std;
class Maths
{
public:
static void Maths::Intro()
{
cout << "You can execute up to 4 mathematical operations:\n";
cout << "\tAdd\t\t1\n";
cout << "\tSubtract\t2\n";
cout << "\tMulitply\t3\n";
cout << "\tDivide\t\t4\n\n";
cout << "Which one you want to perform?\n(Type the number of the operation)\n";
}
static int Maths::Add(int num1, int num2)
{
return num1 + num2;
}
static int Maths::Subtract(int num1, int num2)
{
return num1 - num2;
}
static int Maths::Multiply(int num1, int num2)
{
return num1 * num2;
}
static int Maths::Divide(int num1, int num2)
{
return num1 / num2;
}
};
int _tmain(int argc, _TCHAR* argv[])
{
int res, num1, num2;
Maths::Intro();
cin >> res;
cout << "Now put the first number: ";
cin >> num1;
cout << "\nNow put the second number: ";
cin >> num2;
switch (res)
{
case 1:
cout << num1 << " + " << num2 << " = " << Maths::Add(num1, num2);
break;
case 2:
cout << num1 << " - " << num2 << " = " << Maths::Subtract(num1, num2);
break;
case 3:
cout << num1 << " * " << num2 << " = " << Maths::Multiply(num1, num2);
break;
case 4:
cout << num1 << " / " << num2 << " = " << Maths::Divide(num1, num2);
break;
default:
cout << "It wasn't possible to perform the desired operation";
}
cin >> res;
return 0;
}
-
If you're using VC++ 6 then you can do this:
Menu Build->Set Active Configuration
Choose Win32 Release.
The default configuration mode is debug. This means that your exe contains a lot of debug information, which is responsible for the extra k's.
-
Whoops, I don't hope you have this in your code: <img src="images/smilies/biggrin.gif" border="0" alt="">
:D
-
actually i have...whats the prob?
jk... it was the forum whom translated that wrong lol
-
hmm now it got down to the 100k...but is a bit much i think...i had the idea c++ apps were smaller than vb ones!
-
That's the C++ iostream.
No, C++ apps are not necessarily smaller than VB apps. Especially when they are small and you link to the runtimes statically.
Static linking increases your exe size but the exe is standalone - it doesn't need any runtimes. So you have either large apps or small apps that need runtimes.
VB apps on the other hand are large AND need runtimes.
You can choose whether to link statically or dynamically to the CRT and C++ Library by going to the project options and changing C/C++ -> Code Generation -> Runtime Library.
-
You dont have to use iostream and fstream. I use Standard File IO and Standard Output - gives me executables in < 36 kb!
Code:
#include <iostream>
using namespace std;
Code:
#include <stdlib.h>
-
Yes, but the streams are easier to use and typesafe.
Not to forget that they fit more into C++ philosophy and allow you overloading the stream insertion/extraction operators.