cout function

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • Jahan zaib butt
    New Member
    • Oct 2007
    • 1

    #1

    cout function

    Hi all,
    I have take some inputs from user i variable a and b and want to show them using cout function
    i have used this code

    Code:
    cout<<"Numbers are %d and %d",a,b;
    and the outout is

    Numbers are %d and %d

    What is the problem with my code.
    Thanx
  • sanctus
    New Member
    • Mar 2007
    • 84

    #2
    Originally posted by Jahan zaib butt
    Hi all,
    I have take some inputs from user i variable a and b and want to show them using cout function
    i have used this code

    Code:
    cout<<"Numbers are %d and %d",a,b;
    and the outout is

    Numbers are %d and %d

    What is the problem with my code.
    Thanx
    Without using % it seems easier to me:
    Code:
    cout<<"numbers are:  "<<a<<"   "<<b;
    I never used %d so I can't help you if you want to stick to that.

    Comment

    • Banfa
      Recognized Expert Expert
      • Feb 2006
      • 9067

      #3
      Originally posted by sanctus
      I never used %d so I can't help you if you want to stick to that.
      %d is a format specifier that is used with printf (which you will probably be unaware of if you have leart C++ as opposed to C)

      Jahan zaib butt the printf format specifiers do not work with cout, you need to look up how cout works which is rather different with it's own set of idiosychrocies. Do not try to mix and match because as you have discovered it doesn't work.

      Comment

      Working...