Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C / C++ / MFC
  4. cout vs printf execution sequence

cout vs printf execution sequence

Scheduled Pinned Locked Moved C / C++ / MFC
visual-studio
5 Posts 5 Posters 1 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.
  • M Offline
    M Offline
    MANJUNATH from Bangalore
    wrote on last edited by
    #1

    #include #include void main() { cout<<"cout is executed"<

    P C A D 4 Replies Last reply
    0
    • M MANJUNATH from Bangalore

      #include #include void main() { cout<<"cout is executed"<

      P Offline
      P Offline
      pasztorpisti
      wrote on last edited by
      #2

      This is most probably a result of buffering of the output streams. I would bet that depending on the scenario/platform/compiler you could get different results with this very same code. Don't write such code or flush the streams if you want to guarantee write order.

      1 Reply Last reply
      0
      • M MANJUNATH from Bangalore

        #include #include void main() { cout<<"cout is executed"<

        C Offline
        C Offline
        Captain Price
        wrote on last edited by
        #3

        Why are you trying to use both functions at once ? Is there any advantage ?

        "If A is a success in life, then A=x+y+z. (Work is x; y is play; and z is keeping your mouth shut.)"

        1 Reply Last reply
        0
        • M MANJUNATH from Bangalore

          #include #include void main() { cout<<"cout is executed"<

          A Offline
          A Offline
          Aescleal
          wrote on last edited by
          #4

          If you're using a standard C++ compiler then the cout should happen first. However as you're not using a standard compiler (cout and printf are members of the std namespace for a standard compiler) then all bets are off. Get a new compiler and see if you have the same problem.

          1 Reply Last reply
          0
          • M MANJUNATH from Bangalore

            #include #include void main() { cout<<"cout is executed"<

            D Offline
            D Offline
            David Crow
            wrote on last edited by
            #5

            What if you called "flush" at the end of each? Does it make a difference?

            "One man's wage rise is another man's price increase." - Harold Wilson

            "Fireproof doesn't mean the fire will never come. It means when the fire comes that you will be able to withstand it." - Michael Simmons

            "Show me a community that obeys the Ten Commandments and I'll show you a less crowded prison system." - Anonymous

            1 Reply Last reply
            0
            Reply
            • Reply as topic
            Log in to reply
            • Oldest to Newest
            • Newest to Oldest
            • Most Votes


            • Login

            • Don't have an account? Register

            • Login or register to search.
            • First post
              Last post
            0
            • Categories
            • Recent
            • Tags
            • Popular
            • World
            • Users
            • Groups