Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. [SOLVED] What's happened with my cout<< ?
Forum Updated to NodeBB v4.3 + New Features

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

Scheduled Pinned Locked Moved General and Desktop
3 Posts 2 Posters 1.3k Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • C Offline
    C Offline
    cout Eureka
    wrote on last edited by
    #1

    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@

    1 Reply Last reply
    0
    • VRoninV Offline
      VRoninV Offline
      VRonin
      wrote on last edited by
      #2

      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

      "La mort n'est rien, mais vivre vaincu et sans gloire, c'est mourir tous les jours"
      ~Napoleon Bonaparte

      On a crusade to banish setIndexWidget() from the holy land of Qt

      1 Reply Last reply
      0
      • C Offline
        C Offline
        cout Eureka
        wrote on last edited by
        #3

        thank you for your response !

        Have a nice evening.

        1 Reply Last reply
        0

        • Login

        • Login or register to search.
        • First post
          Last post
        0
        • Categories
        • Recent
        • Tags
        • Popular
        • Users
        • Groups
        • Search
        • Get Qt Extensions
        • Unsolved