Thread: large exe file, and general C++ newbie confusion

  1. #16
    Registered User
    Join Date
    May 2003
    Posts
    1,619
    As a general rule, if you're going to ever do a serious project, I'd advise to never use the 'using' keyword. Use std::cout, std::string, etc. instead. It's better form, and in the end it makes code more readable, especially when you're working with functions from many different namespaces.

    I know on the basic things that beginners do, "using namespace std" works fine, but I feel it sets people up for bad habits later on. It effectively removes the entire benefit that namespaces provide. So my advice is, rather than starting with "using" and later unlearning it, start off where you'll end up.

    This is how I'd code that:

    Code:
    #include <iostream>
    
    int main()
    { 
        char x;
        std::cout << "Type c and press enter" << std::endl;
        std::cin >> x;
    }
    It's not truly necessary to return 0; after main(), because a return 0; is implicit if there's no other return statement.

    Adding std::endl will add a line break after the text.

    Any text/website recommending iostream.h is extremely outdated C++, iostream is the new header, and has been for many years now. That would be a good sign to move on to a better tutorial.
    You ever try a pink golf ball, Wally? Why, the wind shear on a pink ball alone can take the head clean off a 90 pound midget at 300 yards.

  2. #17
    Registered User
    Join Date
    Mar 2006
    Posts
    725
    I believe it's because the libstd++ streams library in MinGW (the compiler Dev-C++ uses) consist of large heirachies of inherited classes, all linking to static libraries; the MinGW gcc compiler is very conservative about removing seemingly unneeded code IIRC. If you want a small executable you can

    1) build on Linux
    2) use Cgywin DLLs and reduce your program's portability a cinch
    3) use some other compiler (you can still use them from within Dev-C++ if you fiddle around with the settings a bit)
    4) use <stdio.h> and the C functions
    5) write your own tiny "pocket-size" streams library (yeah, I've done it before)

    You can also disable debugging symbols and enable executable stripping... check in Tools -> Compiler Options -> Settings.
    Code:
    #include <stdio.h>
    
    void J(char*a){int f,i=0,c='1';for(;a[i]!='0';++i)if(i==81){
    puts(a);return;}for(;c<='9';++c){for(f=0;f<9;++f)if(a[i-i%27+i%9
    /3*3+f/3*9+f%3]==c||a[i%9+f*9]==c||a[i-i%9+f]==c)goto e;a[i]=c;J(a);a[i]
    ='0';e:;}}int main(int c,char**v){int t=0;if(c>1){for(;v[1][
    t];++t);if(t==81){J(v[1]);return 0;}}puts("sudoku [0-9]{81}");return 1;}

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Newbie homework help
    By fossage in forum C Programming
    Replies: 3
    Last Post: 04-30-2009, 04:27 PM
  2. General Guidelines on Preventing Header File collision
    By stanlvw in forum C++ Programming
    Replies: 12
    Last Post: 07-05-2008, 04:02 AM
  3. general C++ help - compilers, file access etc
    By scary_dave in forum C++ Programming
    Replies: 6
    Last Post: 05-06-2006, 09:03 PM
  4. simulate Grep command in Unix using C
    By laxmi in forum C Programming
    Replies: 6
    Last Post: 05-10-2002, 04:10 PM
  5. what does this mean to you?
    By pkananen in forum C++ Programming
    Replies: 8
    Last Post: 02-04-2002, 03:58 PM