Thread: C++ snippet Archive

  1. #1
    Registered User
    Join Date
    Dec 2006
    Posts
    6

    C++ snippet Archive

    I found a great c++ snippet archive
    http://davidw.awardspace.com/index.p...rograming.html
    why dont i see more great web pages like this one??
    please post any links for pages containing whitty little functions like the one above

  2. #2
    Just Lurking Dave_Sinkula's Avatar
    Join Date
    Oct 2002
    Posts
    5,005
    Quote Originally Posted by squako
    why dont i see more great web pages like this one??
    Where I stopped skimming:
    Code:
    while (! myread.eof() )
    Perhaps because the originator needs to learn a little more first?

    [Visit the FAQ to see why. If you go against an FAQ, count yourself in the beginners-intermediate group.]
    7. It is easier to write an incorrect program than understand a correct one.
    40. There are two ways to write error-free programs; only the third one works.*

  3. #3
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,656
    Beh, the site saw me coming, and refused to let me in to have a look....
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.

  4. #4
    MFC killed my cat! manutd's Avatar
    Join Date
    Sep 2006
    Location
    Boston, Massachusetts
    Posts
    870
    Nice broken link...
    Silence is better than unmeaning words.
    - Pythagoras
    My blog

  5. #5
    (?<!re)tired Mario F.'s Avatar
    Join Date
    May 2006
    Location
    Ireland
    Posts
    8,446
    - The user input snippet is awesome!

    - I also like the delay snippet. It's important to put your processor at 100% when delaying an action.

    - The Combine Two Strings function is essential! It's easier to call a function with the prototype string addstrings(string a,string b) than to write a + b!

    I also like using namespace std; all over the place, overflowing ints here and there, the caring concern for proper indentation, the use of C-style casts and this particular snippet of code to convert a string to a float got itself a place in my heart.

    Code:
    template <class T>
    bool from_string(T& t,
    const std::string& s,
    std::ios_base& (*f)(std::ios_base&))
    {
    std::istringstream iss(s);
    return !(iss >> f >> t).fail();
    }
    The masterful indentation, the little detail of breaking the function header in two lines and the absolute geniality behind this useless... useful piece of code.

    EDIT: Are you the author of this, one-time poster? *bows*
    Originally Posted by brewbuck:
    Reimplementing a large system in another language to get a 25% performance boost is nonsense. It would be cheaper to just get a computer which is 25% faster.

  6. #6
    Registered User Tonto's Avatar
    Join Date
    Jun 2005
    Location
    New York
    Posts
    1,465
    Vulnerable.

  7. #7
    Registered User
    Join Date
    Dec 2006
    Posts
    6
    its not good c++??
    it worked for me.

    do you know of a page that has a bunch of c++ operations like this that are better? Please share Because i haven't been able to find it. Thats really why i posted this thread.

  8. #8
    Cat without Hat CornedBee's Avatar
    Join Date
    Apr 2003
    Posts
    8,895
    Quote Originally Posted by squako
    its not good c++??
    it worked for me.
    Those two properties traditionally have no relation in C++.

    http://www.boost.org/

    Familiarize yourself with what is offered by this site. It offers an astounding amount of stuff, written by some of the best C++ programmers out there.
    All the buzzt!
    CornedBee

    "There is not now, nor has there ever been, nor will there ever be, any programming language in which it is the least bit difficult to write bad code."
    - Flon's Law

  9. #9
    Registered User
    Join Date
    Dec 2006
    Posts
    6
    EDIT: Are you the author of this, one-time poster? *bows*
    yea, i suck at programing in c++, but i can program in it just because of a bunch of code snippets. I figured that would be usefull to someone else. But if its terrible c++, i dont want to loose respect of all the c code masters.
    I took the page down.

  10. #10
    Registered User
    Join Date
    Dec 2006
    Posts
    6
    can you guys tell me they easy way to set up a c++ option parser?

  11. #11
    Registered User
    Join Date
    Jan 2005
    Location
    Estonia
    Posts
    131
    c++ option parser = ?

  12. #12
    Its hard... But im here swgh's Avatar
    Join Date
    Apr 2005
    Location
    England
    Posts
    1,688
    yea, i suck at programing in c++, but i can program in it just because of a bunch of code snippets.
    If you are finding it hard to learn the language, then get a good beginners book. Looking at code written by proffesionals is likely to get you even more lost and confused. These are people with years of experience. Saying that, everybody has to start at the beginning of somthing new. No one person can ever learn the language inside out and back to front. Its just not possible, its too big. ( C is different, in comparason it is quite a small but complex language ) You just need to learn all the basics, learn them well then put all this into practise with coding your own programs. You then have to pick at the language and take out the bits and preices you "need" to learn for whatever reason you want to program. ( Ie: games ).
    Double Helix STL

  13. #13
    Registered User
    Join Date
    Dec 2006
    Posts
    6
    c++ option parser for command line programs

  14. #14
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,656
    You mean like this - http://clusty.com/search?query=getop...Mozilla-search
    There are many ways (and libraries) to do this for you.
    Or you can be inspired and make your own.
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.

  15. #15
    (?<!re)tired Mario F.'s Avatar
    Join Date
    May 2006
    Location
    Ireland
    Posts
    8,446
    Originally Posted by brewbuck:
    Reimplementing a large system in another language to get a 25% performance boost is nonsense. It would be cheaper to just get a computer which is 25% faster.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Question about making a C++ archive (.a file)
    By meili100 in forum C++ Programming
    Replies: 5
    Last Post: 08-11-2008, 01:54 PM
  2. could not read symbols: Archive has no index?
    By jutirain in forum C++ Programming
    Replies: 8
    Last Post: 11-30-2007, 10:55 AM
  3. Testers wanted - archiving tool.
    By cboard_member in forum Game Programming
    Replies: 25
    Last Post: 08-31-2006, 06:12 AM
  4. Replies: 4
    Last Post: 07-15-2005, 04:10 PM
  5. archive format
    By Nor in forum A Brief History of Cprogramming.com
    Replies: 0
    Last Post: 08-05-2003, 07:01 PM