Thread: Help needed. Simple C++ program.

  1. #16
    Registered User axon's Avatar
    Join Date
    Feb 2003
    Posts
    2,572
    Kleid-0, give it up dude - seriously, why are you still arguing this. There is nothing wrong with indentation....I'm with Hunter, you should throw that Seiwald book in the garbage right away before it'll "eat out your brain and you're going to explode."

    some entropy with that sink? entropysink.com

    there are two cardinal sins from which all others spring: Impatience and Laziness. - franz kafka

  2. #17
    UT2004 Addict Kleid-0's Avatar
    Join Date
    Dec 2004
    Posts
    656
    I'm never giving up! My next code example with have 5000000 gotos! BWHAHAHAHAHAHAHAAA!!! Who's gonna stop me!??!? You guys ain't got nothin'!
    ---EDIT---
    Oohh I was just playing around, I'm getting some negative rep, I'll stop with the goto.
    ---EDIT AGAIN---
    http://www.techonline.com/community/..._article/25527
    read the last pillar, but also read the source from the link on the first paragraph. He went over 2 indentations many times, I must've read things wrong, my bad.
    Last edited by Kleid-0; 01-27-2005 at 12:07 AM.

  3. #18
    Carnivore ('-'v) Hunter2's Avatar
    Join Date
    May 2002
    Posts
    2,879
    The point of that paragraph was:
    Code which moves too quickly from left to right (and back again) mixes major control flow with minor detail.
    He goes on to say:
    Real code of course requires substantial subblocks, necessarily indented, and these subblock will then have their own indentation battles to be fought.
    And then:
    These Seven Pillars of Pretty Code aren't the last word, or even the first word, on good code.
    And
    But for good code they are, I believe, what distinguishes the readable and pretty code from the rest.
    Fair enough; make your code good first, and when you have good code then you can deal with making it pretty. But you don't sacrifice the goodness of your code for prettiness.. it's like marrying an ogre in a bridal dress (pretty outside ugly inside, or covered-up smelly, or any other significance you attach to the image) instead of the paper-bag princess
    Just Google It. √

    (\ /)
    ( . .)
    c(")(") This is bunny. Copy and paste bunny into your signature to help him gain world domination.

  4. #19
    Registered User hk_mp5kpdw's Avatar
    Join Date
    Jan 2002
    Location
    Northern Virginia/Washington DC Metropolitan Area
    Posts
    3,817
    I knew this was possible using concepts I had heard of using facets and locales and things of that nature but I wasn't experienced enough to be able to implement them so this post made me remember one of the books I had been meaning to get "Standard C++ IOStreams and Locales". I went out and bought it from Amazon and splurged on next-day-shipping. Today it came and I finally made an example that deals with this problem after struggling for about an hour of looking through code in the book. It's really really ugly, but I'd like to share...

    Code:
    #include <iostream>
    #include <locale>
    #include <string>
    #include <iterator>
    
    int main()
    {
        std::locale loc(std::locale("American_USA.1252"),
                        new std::num_put<char,std::back_insert_iterator<std::string> >);
        std::basic_ios<char> str(0);
        str.imbue(loc);
        std::string s = "";
        std::use_facet<std::num_put<char,std::back_insert_iterator<std::string> > >(loc)
            .put(std::back_inserter(s),str,' ',(unsigned long)12345678L);
        std::cout << s << std::endl;
    }
    Output:
    Code:
    12,345,678
    I was only able to get this to even compile using a MSVC++ .Net compiler, the old MSVC++ 6.0 I had been using chokes trying to compile it. To me this looks like a lot of work just to print out some commas. Anyone else have experience with this stuff? I have to believe there is an easier way to use this stuff.

    I'm NOT recommending this for the original poster, just thought if anyone had seen stuff like this before and knew a better way...
    "Owners of dogs will have noticed that, if you provide them with food and water and shelter and affection, they will think you are god. Whereas owners of cats are compelled to realize that, if you provide them with food and water and shelter and affection, they draw the conclusion that they are gods."
    -Christopher Hitchens

  5. #20
    Redundantly Redundant RoD's Avatar
    Join Date
    Sep 2002
    Location
    Missouri
    Posts
    6,331
    use gotos if you want, but your the reason people think "void main" is C++, and its not. Teaching bad habits does noone any good.

  6. #21
    UT2004 Addict Kleid-0's Avatar
    Join Date
    Dec 2004
    Posts
    656
    I see what you mean RoD.

    But I see void main() as being more of a bug, and goto would just a code reading problem. But I'll stop the goto because I'm starting to see a pattern with my usage. If my small programs use goto, God only knows what I'm going to be doing with goto 5 years from now... :(

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Program Plan
    By Programmer_P in forum C++ Programming
    Replies: 0
    Last Post: 05-11-2009, 01:42 AM
  2. Simple Blackjack Program
    By saber1357 in forum C Programming
    Replies: 1
    Last Post: 03-28-2009, 03:19 PM
  3. Client-server system with input from separate program
    By robot-ic in forum Networking/Device Communication
    Replies: 3
    Last Post: 01-16-2009, 03:30 PM
  4. Mystery bug in simple program? - I am beginner
    By archie123 in forum C++ Programming
    Replies: 7
    Last Post: 04-08-2005, 07:23 AM
  5. Help with small simple program
    By Sonor in forum C Programming
    Replies: 5
    Last Post: 04-02-2005, 07:40 AM