Wednesday, May 18, 2011

STL = a pure computation library for C++ (amazing)

The C++ STL or Standard Template Library can easily be divided into two sections, algorithms and containers.
The version you will find accompanying most modern C++ compilers is based off of the SGI version of the STL which can be used alternatively.

Many programmers can find some utility in using the STL as it can make computation as easy as pie.  For example, every permutation of "abcdefghijklmnopqrstuvwxyz"




#include <iostream>
#include <string>
#include <algorithm>



int main()
{
   using namespace std;
   string input = "abcdefghijklmnopqrstuvwxyz";
   do
   {
       cout << input << "\n";
   }while( std::next_permutation(input.begin(), input.end()) );
}

20 comments:

  1. Great post! I like your blog!

    ReplyDelete
  2. never had a need to perform such complex algorithms in my programs but im still a beginner. really enjoy these posts theyre really helping me remember my code :D keep it up!

    ReplyDelete
  3. you don't happen to know python by any chance do you?

    ReplyDelete
  4. @AOmar, not really.

    C, C++, C++/CLI, C#, and a little bit of Java.

    But hey I still might be able to provide some assistance unless it's very python-specific.

    ReplyDelete
  5. I'm not going to pretend that I understand any of this!

    ReplyDelete
  6. Thanks. I will have to use this.

    ReplyDelete
  7. Java seems to be very much alike, from first sight.

    ReplyDelete
  8. I really need to learn some C :s
    Got as far as a hello world program and said "Good enough." Haha.

    ReplyDelete
  9. I wish I knew what this post was about. Programing sounds like a lot of fun!

    ReplyDelete
  10. Im interested in this stuff, but I really don't understand any of the technical terms..=( Followed though, maybe later on when i start to get it ill come back ;)

    ReplyDelete
  11. @CounterCulture:

    Something very useful when learning C/C++ is a good reference.

    http://www.cplusplus.com/reference/

    For printf we see: http://www.cplusplus.com/reference/clibrary/cstdio/printf/

    The "..." in the prototype at the top means it is able to accept any number of arguments.

    "printf("Hello C!");"

    ReplyDelete
  12. this is really interesting, I've always wanted to learn programming languages

    ReplyDelete
  13. thanks for sharing these sample codes, these will come in handy the next time that i wanna program something in c

    I have followed your blog..Could you follow mine too please? Also check out my guest blogging contest to see if you are interested!

    Sky Stock Analysis

    ReplyDelete
  14. I need to get more knowledge about software, i'll follow :)

    ReplyDelete
  15. i should have stuck with C++ could have made something cool :(

    ReplyDelete
  16. @Duke,

    In my opinion C++ is a more professional sort of language and is used when performance is necessary; most smaller applications are easier to create with one of the "butterknife" languages like C# or Java.

    That being said, there are still plenty of benefits to learning C++, for instance access to the operating system API (without pInvoking everywhere).

    There's also something just not quite right about putting a managed GUI interface on a C++ application.

    One problem with C++ is that it has no standard way of creating a graphical user interface, it depends entirely on the operating system. For the Microsoft Windows platform there are plenty of ways to abstract the gory details of the raw Win API with C++. Many are in the form of a library like QT or wxWidgets.

    ReplyDelete
  17. this is really interesting, I wanna start doing C++ in the upcoming summer vacation

    ReplyDelete
  18. This reminds me that I should stop procrastinate and start a project.

    ReplyDelete
  19. That is pretty convenient. I shouldn't have stopped learning C++ when I did. Maybe I'll start up again.

    ReplyDelete
  20. Can i say i'm lost? lol great tips!

    ReplyDelete