[SOLVED] What's happened with my cout<< ?



  • Hello Qt World !

    Is there somebody can explane at me why the display is different ? It's very strange !
    @#include <iostream>

    int add(int & a)
    {
    a += 1;
    return a;
    }

    void enUneLigne();
    void enPlusieursLignes();

    int main()
    {
    std::cout << "en une ligne:" << std::endl;
    enUneLigne();
    std::cout << std::endl << std::endl << "en plusieurs lignes:" << std::endl;
    enPlusieursLignes();
    return 0;
    }

    void enUneLigne()
    {
    int a(0);

    std::cout <<
    "1: " << add(a) << std::endl <<
    "2: " << add(a) << std::endl <<
    "3: " << add(a) << std::endl <<
    "4: " << add(a) << std::endl;
    

    }
    void enPlusieursLignes()
    {
    int a(0);

    std::cout << "1: " << add(a) << std::endl;
    std::cout << "2: " << add(a) << std::endl;
    std::cout << "3: " << add(a) << std::endl;
    std::cout << "4: " << add(a) << std::endl;
    

    }
    @

    the display :

    @Démarrage de \QT Projects_Essai4\debug_Essai4.exe...en une ligne:
    1: 4
    2: 3
    3: 2
    4: 1

    en plusieurs lignes:
    1: 1
    2: 2
    3: 3
    4: 4
    \QT Projects_Essai4\debug_Essai4.exe a quitté avec le code 0@



  • This has nothing to do with Qt. the fact is just that C and C++ execute commands "from right to left" so the first function that is called in the enUneLigne() function is the one related to the fourth line of the text



  • thank you for your response !

    Have a nice evening.


Log in to reply
 

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.