I want to set fmtflag

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • mohamed azaz

    I want to set fmtflag

    hi
    I want to set a format flag what is the right code


    example


    format flag as (right)or(left)


    thank you


    bye


  • Jeff Schwab

    #2
    Re: I want to set fmtflag

    mohamed azaz wrote:
    I want to set a format flag what is the right code
    example
    format flag as (right)or(left)
    It is not clear what you need. Could you please post some sample code,
    or some pseudo-code showing what you need? A small example, with
    comments instead of code for the part you're not sure about, would be a
    big help.

    Comment

    • mohamed azaz

      #3
      Re: I want to set fmtflag

      cout.setf(ios:: left); // left justify output text
      cout >"This text is left-justified";
      cout.unsetf(ios ::left); // return to default (right justified)

      this code doesn't work

      Comment

      • Jeff Schwab

        #4
        Re: I want to set fmtflag

        mohamed azaz wrote:
        cout.setf(ios:: left); // left justify output text
        cout >"This text is left-justified";
        cout << "This text is left-justified";
        cout.unsetf(ios ::left); // return to default (right justified)
        >
        this code doesn't work
        The problem has nothing to do with the flags. You have used the
        extraction operator (>>) when you needed the insertion operator (<<).
        The arrows indicate the direction of information flow: During
        extraction, a value is moved from the stream to the variable (stream >>
        variable). During insertion, a value is moved from the variable to the
        stream (stream << variable).

        Comment

        Working...