CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Page 4 of 5 FirstFirst 12345 LastLast
Results 46 to 60 of 64
  1. #46
    Join Date
    Nov 2002
    Location
    Sofia, Bulgaria
    Posts
    661
    what happened to the
    obfuscated "Hello world!" application
    ??!?!??!?!?!?1
    It's only when you look at an ant through a magnifying glass on a sunny day that you realise how often they burst into flames

  2. #47
    Join Date
    Jun 2001
    Location
    Switzerland
    Posts
    4,443
    Code:
    #include <iostream>
    #include <list>
    #include <boost/any.hpp>
    #include <algorithm>
    using namespace std;
    
    typedef list<boost::any> lany;
    
    template <typename T>void Larry(T t){}
    template <>void Larry(int t){if(t) cout<<"H"; else cout<<"d";}
    template <>void Larry(float t){if(!t) cout<<"e"; else cout<<"l";}
    template <>void Larry(bool t){if(t) cout<<"o"; else cout<<" ";}
    template <>void Larry(double t){if(t) cout<<"w"; else cout<<"r";}
    template <>void Larry(char t){if(t) cout<<"!"; else cout<<"\n";}
    
    void Jimmy( const boost::any & Any)
    {
        try{Larry(boost::any_cast<int>   (Any));}  catch(boost::bad_any_cast&){}
        try{Larry(boost::any_cast<float> (Any));}  catch(boost::bad_any_cast&){}
        try{Larry(boost::any_cast<bool>  (Any));}  catch(boost::bad_any_cast&){}
        try{Larry(boost::any_cast<double>(Any));}  catch(boost::bad_any_cast&){}
        try{Larry(boost::any_cast<char>  (Any));}  catch(boost::bad_any_cast&){}
    }
    
    int main()
    {
        lany Lany;
        Lany.push_back(boost::any(1));
        Lany.push_back(boost::any(0.0f));
        Lany.push_back(boost::any(1.0f));
        Lany.push_back(boost::any(1.0f));
        Lany.push_back(boost::any(true));
        Lany.push_back(boost::any(false));
        Lany.push_back(boost::any(1.0));
        Lany.push_back(boost::any(true));
        Lany.push_back(boost::any(0.0));
        Lany.push_back(boost::any(1.0f));
        Lany.push_back(boost::any(0));
        Lany.push_back(boost::any('x'));
        Lany.push_back(boost::any('\0'));
        for_each(Lany.begin(), Lany.end(), Jimmy);
        return 0;
    }
    Gabriel, CodeGuru moderator

    Forever trusting who we are
    And nothing else matters
    - Metallica

    Learn about the advantages of std::vector.

  3. #48
    Join Date
    Sep 2002
    Location
    Maryland - Fear The Turtle!
    Posts
    7,537
    Originally posted by galathaea
    Hmm, I think I still don't get it.....
    well you got the purple part which other part are you not getting...

  4. #49
    Join Date
    Apr 2003
    Posts
    893
    Originally posted by Gabriel Fleseriu
    Code:
    #include <iostream>
    #include <list>
    #include <boost/any.hpp>
    #include <algorithm>
    using namespace std;
    
    typedef list<boost::any> lany;
    
    template <typename T>void Larry(T t){}
    template <>void Larry(int t){if(t) cout<<"H"; else cout<<"d";}
    template <>void Larry(float t){if(!t) cout<<"e"; else cout<<"l";}
    template <>void Larry(bool t){if(t) cout<<"o"; else cout<<" ";}
    template <>void Larry(double t){if(t) cout<<"w"; else cout<<"r";}
    template <>void Larry(char t){if(t) cout<<"!"; else cout<<"\n";}
    
    void Jimmy( const boost::any & Any)
    {
        try{Larry(boost::any_cast<int>   (Any));}  catch(boost::bad_any_cast&){}
        try{Larry(boost::any_cast<float> (Any));}  catch(boost::bad_any_cast&){}
        try{Larry(boost::any_cast<bool>  (Any));}  catch(boost::bad_any_cast&){}
        try{Larry(boost::any_cast<double>(Any));}  catch(boost::bad_any_cast&){}
        try{Larry(boost::any_cast<char>  (Any));}  catch(boost::bad_any_cast&){}
    }
    
    int main()
    {
        lany Lany;
        Lany.push_back(boost::any(1));
        Lany.push_back(boost::any(0.0f));
        Lany.push_back(boost::any(1.0f));
        Lany.push_back(boost::any(1.0f));
        Lany.push_back(boost::any(true));
        Lany.push_back(boost::any(false));
        Lany.push_back(boost::any(1.0));
        Lany.push_back(boost::any(true));
        Lany.push_back(boost::any(0.0));
        Lany.push_back(boost::any(1.0f));
        Lany.push_back(boost::any(0));
        Lany.push_back(boost::any('x'));
        Lany.push_back(boost::any('\0'));
        for_each(Lany.begin(), Lany.end(), Jimmy);
        return 0;
    }
    Gabriel, what does this program mean ?...ahmm.. what is the include<... .hpp > used for ?
    Thank you veru much...
    Regards

  5. #50
    Join Date
    Jun 2001
    Location
    Switzerland
    Posts
    4,443
    Originally posted by hometown
    Gabriel, what does this program mean ?...ahmm.. what is the include<... .hpp > used for ?
    Thank you veru much...
    Regards
    As (almost) every program in this thread, this one also prints "Hello world!". I find it rather funny than obfuscated. The extension ".hpp" is a header extension. The boost library (www.boost.org) uses it.

    Does this answer your question, or do you want to know how it works?
    Gabriel, CodeGuru moderator

    Forever trusting who we are
    And nothing else matters
    - Metallica

    Learn about the advantages of std::vector.

  6. #51
    Join Date
    Apr 2003
    Posts
    893

    Thank you Gabriel,

    You mean if I would like to use such a .hpp file I will have to download it from boost ?

    But what is that header file used for ?

  7. #52
    Join Date
    Jun 2001
    Location
    Switzerland
    Posts
    4,443

    Re: Thank you Gabriel,

    Originally posted by hometown
    You mean if I would like to use such a .hpp file I will have to download it from boost ?

    But what is that header file used for ?
    If you want to use any of the boost' libraries, then yes, you will have to download them from boost. That doesn't mean that you are not allowed to name your own headers "something.hpp". The extension .hpp is as good as .h -- actually it signals that the header is C++ specific (.c vs. .cpp --> .h vs. .hpp);

    <boost/any.hpp> is the header that implements the class boost::any. To make a long story short, this class can hold (nearly) any type of variable -- thus the name. Read the boost documentation if you want to know more.
    Gabriel, CodeGuru moderator

    Forever trusting who we are
    And nothing else matters
    - Metallica

    Learn about the advantages of std::vector.

  8. #53
    Join Date
    Apr 2003
    Posts
    893

    Thank you Gabriel very much...

    Originally posted by Gabriel Fleseriu
    If you want to use any of the boost' libraries, then yes, you will have to download them from boost. That doesn't mean that you are not allowed to name your own headers "something.hpp". The extension .hpp is as good as .h -- actually it signals that the header is C++ specific (.c vs. .cpp --> .h vs. .hpp);

    <boost/any.hpp> is the header that implements the class boost::any. To make a long story short, this class can hold (nearly) any type of variable -- thus the name. Read the boost documentation if you want to know more.

  9. #54
    Join Date
    Dec 2001
    Location
    Ontario, Canada
    Posts
    2,236
    The file extension really doesn't matter, some people do like the hpp, but the standard library has no file extension. You could make up an extension and as long as your compiler knows its a header file it will compile.

  10. #55
    Join Date
    Apr 2003
    Posts
    893

    Thank you very much...

    Originally posted by mwilliamson
    The file extension really doesn't matter, some people do like the hpp, but the standard library has no file extension. You could make up an extension and as long as your compiler knows its a header file it will compile.
    I tried making a bunch of files with different extensions, and they all work fine
    Thank you very much...

  11. #56
    Join Date
    Dec 2002
    Posts
    1,050
    Gabriel Fleseriu
    quote:
    --------------------------------------------------------------------------------
    Originally posted by galathaea
    Gabriel, your post is nonstandard because it assumes an ANSI character set...
    --------------------------------------------------------------------------------
    Bingo!
    I can't find this part of the standard. What page is this
    mentioned on ?
    And are you talking about wchar_t /vs char or am I missing
    something.

  12. #57
    Join Date
    Jun 2001
    Location
    Switzerland
    Posts
    4,443
    Originally posted by mdmd
    I can't find this part of the standard. What page is this
    mentioned on ?
    And are you talking about wchar_t /vs char or am I missing
    something.
    The Standard does not say that the target platform has to have an ASCII character set. For example, some IBM computers use the so called EBCDIC character set, if my memory serves me correctly. If you run my program on such a machine, it printed some bogus string.
    Gabriel, CodeGuru moderator

    Forever trusting who we are
    And nothing else matters
    - Metallica

    Learn about the advantages of std::vector.

  13. #58
    Join Date
    May 2003
    Location
    V–|ÉÇβ
    Posts
    26
    oh~~ fantastic~~

  14. #59
    Join Date
    Nov 1999
    Location
    Copenhagen, Denmark
    Posts
    265

    A minimal "Hello, world!".

    This should be fairly standard:

    Code:
    #include <sstream>
    #include <algorithm>
    #include <iostream>
    
    template <class X> class K
    {
    	std::basic_string<X> b, s;
    public:
    	K(const std::basic_string<X> &z) : b(z) 	
    	{ 
    		std::for_each(++(s = static_cast<std::ostringstream *>(&(std::ostringstream() << std::endl << 
    			"!dlrow olleH" << std::ends))->str()).rbegin(), s.rend(), *this);
    	}
    	void operator()(std::basic_string<X>::value_type &d) const 
    	{ 
    		if(b.find(d) == std::basic_string<std::basic_string<X>::value_type>::npos) std::cout << d; 
    	}
    };
    
    int main() 
    {
    	K<char> k("abcfgijkmnpqstuvxyz");
    	return 0;
    }
    Best regards,
    S. Bro

    "I would be happy to deal with my problems one at the time if they would only line up!"
    -Paul Cilwa, "Borland C++ Insider".

    Other useful fora some of which I ruthlessly clipboarded from other peoples footers.

    MSDN: http://search.microsoft.com/us/dev/default.asp
    WIN 32 Assembler: http://board.win32asmcommunity.net/
    RDBMS: http://www.dbforums.com
    Robert's Perl Tutorial: http://www.sthomas.net/roberts-perl-tutorial.htm
    Merriam-Webster Online: http://www.m-w.com/home.htm
    Writing Unmaintainable Code: http://mindprod.com/unmain.html

  15. #60
    Join Date
    Oct 2002
    Location
    Timisoara, Romania
    Posts
    14,360
    Something easy to understand:

    Code:
    #include <iostream>
    #include <vector>
    #include <string>
    #include <algorithm>
    #include <functional>
    
    using namespace std;
    
    typedef vector<string> StringVector;
    
    typedef StringVector::iterator StringVectorIterator;
    
    typedef ostream_iterator<string> StringOstreamIterator;
    
    int main(int argc, char* argv[])
    {
        int i;
        const int VECTOR_SIZE = 0x05;
        char limits[] = {'('-1,'7'};
        char mixture[] = {0x1D, 0x27, 0x00, 0x24, 0x24, 0x18, 0x0D, 0x1B, 0x00, 0x15};
    		
        StringVector one_word(VECTOR_SIZE);
        StringVector another_word(VECTOR_SIZE);
    	
        StringVectorIterator start_one_word_it, end_one_word_it;
        StringVectorIterator start_another_word_it, end_another_word_it;
    	
        StringOstreamIterator out_one_word_it(cout, "");
        StringOstreamIterator out_another_word_it(cout, "");
    	
        start_one_word_it = one_word.begin();
        end_one_word_it = one_word.end();
    
        start_another_word_it = another_word.begin();
        end_another_word_it = another_word.end();
    
        for(i =0; i<VECTOR_SIZE; i++)
    	one_word[i] = mixture[i] + 0x48;
        for(; i<VECTOR_SIZE<<1; i++)
    	another_word[i-VECTOR_SIZE] = mixture[i] + 0x57;
    		
        for(i=0; i<limits[0]; i++, next_permutation(start_one_word_it, end_one_word_it));
        for(i=0; i<limits[1]; i++, next_permutation(start_another_word_it, end_another_word_it));
        copy(start_one_word_it, end_one_word_it, out_one_word_it);
        cout << " ";
        copy(start_another_word_it, end_another_word_it, out_another_word_it);
        cout << "!" << endl ;
    	
        return 0;
    }
    Marius Bancila
    Home Page
    My CodeGuru articles

    I do not offer technical support via PM or e-mail. Please use vbBulletin codes.

Page 4 of 5 FirstFirst 12345 LastLast

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured