1. C++ / Говнокод #13789

    +69

    1. 1
    С ДНЕМ МУДАКОВ ЗАДРОТЫ АЗАЗАЗА

    13 СИНТЯБРЯ ДЕНЬ ЛАХОВ И ЗАДРОТАВ
    p.s. мне всево 7 лет и у миня есть ifon 5

    PragramistOtBoga, 13 Сентября 2013

    Комментарии (2)
  2. C++ / Говнокод #13777

    +3

    1. 01
    2. 02
    3. 03
    4. 04
    5. 05
    6. 06
    7. 07
    8. 08
    9. 09
    10. 10
    11. 11
    12. 12
    13. 13
    14. 14
    15. 15
    16. 16
    17. 17
    18. 18
    19. 19
    20. 20
    21. 21
    22. 22
    23. 23
    24. 24
    25. 25
    26. 26
    27. 27
    28. 28
    29. 29
    30. 30
    31. 31
    32. 32
    33. 33
    34. 34
    35. 35
    36. 36
    37. 37
    38. 38
    39. 39
    40. 40
    41. 41
    42. 42
    43. 43
    44. 44
    45. 45
    46. 46
    47. 47
    48. 48
    49. 49
    50. 50
    51. 51
    52. 52
    53. 53
    54. 54
    55. 55
    56. 56
    57. 57
    58. 58
    59. 59
    60. 60
    #include "stdafx.h"
    #include <windows.h>
    #include <iostream>
    #include <stdio.h>
    #include <conio.h>
    using namespace std;
    
    class pop
    {
    public:
    char groupp[10];
    char alb[10];
    char name[10];
    pop vvod()
    {
    pop v;
    cin » v.groupp;
    cin » v.alb;
    cin » v.name;
    return v;
    }
    void vivod(pop v)
    {
    cout « v.groupp, "\n";
    cout « v.alb, "\n";
    cout « v.name, "\n";
    }
    };
    void main()
    {
    char a;
    int b=1;
    pop v;
    while(b!=0)
    { 
    cout « "vvodite";
    cin »a;
    switch ( a )
    {
    case '1':
    {
    v=v.vvod();
    b=1;
    break;
    }
    case '2':
    {
    v.vivod(v);
    b=1;
    break;
    }
    default :
    {
    system("cls");
    b=0;
    }
    }
    }
    
    }

    high-five, 11 Сентября 2013

    Комментарии (41)
  3. C++ / Говнокод #13745

    +14

    1. 01
    2. 02
    3. 03
    4. 04
    5. 05
    6. 06
    7. 07
    8. 08
    9. 09
    10. 10
    11. 11
    12. 12
    13. 13
    14. 14
    15. 15
    16. 16
    17. 17
    18. 18
    19. 19
    20. 20
    21. 21
    22. 22
    23. 23
    24. 24
    25. 25
    26. 26
    27. 27
    28. 28
    29. 29
    30. 30
    31. 31
    32. 32
    constexpr const char str1[] = "Anna";
    constexpr const char str2[] = "Denis";
    constexpr const char str3[] = "Vladimir";
    constexpr const char str4[] = "Alexey";
    
    constexpr const char *arr[] = { str1, str2, str3, str4 };
    
    #define GetMaxLenght(array) \
    constexpr unsigned char str_len(const char* const str) \
    {\
       return *str ? (1 + str_len(str + 1)) : 0;\
    }\
    \
    template <int index> \
    struct MaxLenght\
    {\
        static const int prev_size = MaxLenght<index-1>::max_size;\
        static const int cur_size = str_len(array[index]);\
        static const int max_size = cur_size > prev_size ? cur_size : prev_size;\
    };\
    \
    template <>\
    struct MaxLenght<-1>\
    {\
        static const int max_size = 0;\
    };\
    static const int AmountStr = sizeof(array) / sizeof(array[0]);\
    static const int array##_max_size = MaxLenght<AmountStr-1>::max_size;
    GetMaxLenght(arr);
    
    //   в *.cpp
    //   static_assert((arr_max_size == 8), "Error");

    http://habrahabr.ru/post/192736/

    LispGovno, 06 Сентября 2013

    Комментарии (22)
  4. C++ / Говнокод #13743

    +2

    1. 01
    2. 02
    3. 03
    4. 04
    5. 05
    6. 06
    7. 07
    8. 08
    9. 09
    10. 10
    11. 11
    12. 12
    13. 13
    14. 14
    15. 15
    16. 16
    17. 17
    double vvod (double a1, double a2, double a3) {
     
    // a1=a a2=b a3=c
     
    	cout<<"Введите значение коэфицента a: ";
    	cin>>a1;
    	cout<<endl;
    	cout<<"Введите значение коэфицента b: ";
    	cin>>a2;
    	cout<<endl;
    	cout<<"Введите значение коэфицента c: ";
    	cin>>a3;
    	cout<<endl;
    	return (a1);
    	return (a2);
    	return (a3);
    }

    Оказывается в С++ можно возвращать 3 значения из функции
    http://ideone.com/tGWRpl - полная версия.

    pabloid, 05 Сентября 2013

    Комментарии (51)
  5. C++ / Говнокод #13741

    −1

    1. 01
    2. 02
    3. 03
    4. 04
    5. 05
    6. 06
    7. 07
    8. 08
    9. 09
    10. 10
    11. 11
    12. 12
    13. 13
    14. 14
    15. 15
    16. 16
    17. 17
    18. 18
    19. 19
    20. 20
    21. 21
    22. 22
    23. 23
    24. 24
    25. 25
    26. 26
    27. 27
    28. 28
    29. 29
    30. 30
    31. 31
    32. 32
    33. 33
    34. 34
    35. 35
    36. 36
    37. 37
    38. 38
    39. 39
    #include <iostream>
    using namespace std;
    
    struct NG
    {
    	template<class T>
    	struct get
    	{
    		typedef typename T::f type;
    	};
    };
    
    template <typename T, typename NameGetter>
    struct has_member_impl
    {
        typedef char matched_return_type;
        typedef long unmatched_return_type;
        
        template <typename C>
        static matched_return_type f(typename NameGetter::template get<C>*);
        
        template <typename C>
        static unmatched_return_type f(...);
        
    public:
        static const bool value = (sizeof(f<T>(0)) == sizeof(matched_return_type));
    };
    
    template <typename T, typename NameGetter>
    struct has_member{
       enum { value = has_member_impl<T, NameGetter>::value };
     };
     
     class T{};
    
    int main() {
    	cout<<has_member<T, NG>::value;
    	return 0;
    }

    http://ideone.com/4LDGhZ

    LispGovno, 04 Сентября 2013

    Комментарии (36)
  6. C++ / Говнокод #13736

    +13

    1. 1
    2. 2
    3. 3
    4. 4
    5. 5
    6. 6
    7. 7
    8. 8
    9. 9
    TAbstractMessageFrame * SwitchIfNeedReceivePackets = create_switch(
    		fnc_ext::bind(this,
    					  fnc_ext::compose2(std::greater<WORD>(),
    										fnc_ext::get_mem(&TThisClass::_totalDataLength),
    										fnc_ext::compose1(std::bind1st(std::minus<WORD>(), static_cast<WORD>(TByteBuffer::MaxCapacity)),
    														  fnc_ext::compose1(fnc_ext::get_mem_func_ref(&TThisClass::TByteBuffer::length),
    																			fnc_ext::get_mem(&TThisClass::_receivedBuffer))))),
    //										fnc_ext::get_mem_func(&TThisClass::FreeBufferSpace))),
    		DataByPackets, DataByLength, "Switch If Need Receive Packets" );

    Говногость, 04 Сентября 2013

    Комментарии (34)
  7. C++ / Говнокод #13733

    +13

    1. 01
    2. 02
    3. 03
    4. 04
    5. 05
    6. 06
    7. 07
    8. 08
    9. 09
    10. 10
    11. 11
    12. 12
    13. 13
    14. 14
    15. 15
    16. 16
    17. 17
    18. 18
    19. 19
    20. 20
    21. 21
    22. 22
    23. 23
    24. 24
    25. 25
    26. 26
    27. 27
    28. 28
    29. 29
    30. 30
    31. 31
    32. 32
    33. 33
    34. 34
    35. 35
    36. 36
    37. 37
    38. 38
    39. 39
    40. 40
    41. 41
    42. 42
    43. 43
    44. 44
    45. 45
    46. 46
    47. 47
    48. 48
    49. 49
    50. 50
    51. 51
    52. 52
    void User::AddFriend(User& newFriend)
    {
        friends_.push_back(&newFriend);
        pDB_->AddFriend(GetName(), newFriend.GetName());
    }
    
    //...VS...
    
    void User::AddFriend(User& newFriend)
    {
        friends_.push_back(&newFriend);
        try
        {
            pDB_->AddFriend(GetName(), newFriend.GetName());
        }
        catch (...)
        {
            friends_.pop_back();
            throw;
        }
    }
    
    //...VS...
    
    class VectorInserter//Глобальный безопасный вектороВставлятель.
    {
    public:
        VectorInserter(std::vector<User*>& v, User& u)
        : container_(v), commit_(false)
        {
            container_.push_back(&u);
        }
        void Commit() throw()
        {
            commit_ = true;
        }
        ~VectorInserter()
        {
            if (!commit_) container_.pop_back();
        }
    private:
        std::vector<User*>& container_;
        bool commit_;
    };
    
    void User::AddFriend(User& newFriend)
    {
        VectorInserter ins(friends_, &newFriend);
        pDB_->AddFriend(GetName(), newFriend.GetName());
        // Everything went fine, commit the vector insertion
        ins.Commit();
    }

    LispGovno, 03 Сентября 2013

    Комментарии (44)
  8. C++ / Говнокод #13732

    +8

    1. 01
    2. 02
    3. 03
    4. 04
    5. 05
    6. 06
    7. 07
    8. 08
    9. 09
    10. 10
    11. 11
    12. 12
    13. 13
    14. 14
    15. 15
    16. 16
    17. 17
    18. 18
    19. 19
    20. 20
    21. 21
    22. 22
    template<int ID> struct typeof_access
    {
        struct id2type; //not defined
    };
    
    template<class T, int ID> struct typeof_register : typeof_access
    {
        // define base's nested class here
        struct typeof_access::id2type
        {
            typedef T type;
        };
    };
    
    //Type registration function 
    typeof_register<T, compile-time-constant> register_type(const T&);
    
    //Actually register type by instantiating typeof_register for the correct type
    sizeof(register_type(some-type));
    
    //Use the base class to access the type.
    typedef typeof_access::id2type::type type;

    Igor Chesnokov discovered a method that allows to implement typeof on the VC series of compilers. It uses a bug in the Microsoft compiler that allows a nested class of base to be defined in a class derived from base.

    http://www.boost.org/doc/libs/1_54_0/doc/html/typeof/other.html

    LispGovno, 03 Сентября 2013

    Комментарии (6)
  9. C++ / Говнокод #13727

    +14

    1. 1
    2. 2
    struct Ziga : std::exception {};
    throw Ziga();

    Теперь вы знаете как кинуть зигу в C++ !!

    PSIAlt, 02 Сентября 2013

    Комментарии (70)
  10. C++ / Говнокод #13715

    −16

    1. 01
    2. 02
    3. 03
    4. 04
    5. 05
    6. 06
    7. 07
    8. 08
    9. 09
    10. 10
    11. 11
    12. 12
    13. 13
    14. 14
    15. 15
    16. 16
    17. 17
    18. 18
    19. 19
    20. 20
    21. 21
    22. 22
    23. 23
    24. 24
    25. 25
    26. 26
    27. 27
    28. 28
    29. 29
    30. 30
    31. 31
    32. 32
    33. 33
    34. 34
    35. 35
    36. 36
    37. 37
    38. 38
    39. 39
    40. 40
    41. 41
    42. 42
    43. 43
    44. 44
    45. 45
    46. 46
    47. 47
    48. 48
    49. 49
    50. 50
    51. 51
    52. 52
    53. 53
    54. 54
    55. 55
    56. 56
    57. 57
    58. 58
    59. 59
    60. 60
    61. 61
    62. 62
    63. 63
    64. 64
    65. 65
    66. 66
    #include <iostream>
    #include <string>
    
    using namespace std;
    /*
    
    */
    
    int change_word(const int begin_pos, string &words, int k, char c)
    {
        int pos = begin_pos;
        int char_count = 0;
    
        bool replaced = false; 
    
        while(pos < words.length() && isalpha(words[pos]))
        {
    
            char_count++;
            if(char_count == k && !replaced)
            {
                words[pos] = c;
                replaced = true;
    
            }
            pos++;
    
        }
    
        return pos; 
    }
    
    void change_words(string &words, int k, char c)
    {
        int i = 0;
    
        while(i < words.length())
        {
            if(isalpha(words[i]))
            {
                i = change_word(i, words, k, c);
    
            }
            else
            {
                i++;
            }
    
        }
    
    }
    
    
    int main()
    {
        char c = '>'; 
        int k = 0; 
        string words = "Length of the substring to be copied";
    
        cout << "enter number:";
        cin >> k;
        change_words(words, k, c);
    
        cout << "changed text: " << words << endl;
        return 0;
    }

    лаба на с++, заменить в тексте к-тую букву на символ с.

    spivti, 01 Сентября 2013

    Комментарии (71)