• # Je hais le C++

    Posté par . En réponse au journal Moi, expert C++, j'abandonne le C++. Évalué à 1.

    ...mais plutôt qu'un long discours, 2 petits exemples:

    #include <string>
    #include <stdio.h>
    int main()
    {
     std::string s("++123");
     printf("%s\n", s.substr(2).c_str());
     const char *c1 = s.substr(2).c_str();
     printf("%s\n", c1);
     std::string s2 = s.substr(2);
     const char *c2 = s2.c_str();
     printf("%s\n", c2);
    }
    #include <iostream>
    struct A
    {
     A() { std::cout << "A" << std::endl; }
    };
    struct B
    {
     int b;
     B() : b(0) { std::cout << "B" << std::endl; }
     B(int _b) : b(_b) { std::cout << "B " <<b << std::endl; }
    };
    int b = 1;
    int main()
    {
     A();
     B(b);
    }

    Qu'écrivent ces programmes sur la sortie standard ?