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
CODE PROJECT For Those Who Code
  • Home
  • Articles
  • FAQ
Community
  1. Home
  2. General Programming
  3. C / C++ / MFC
  4. User define iostream manipulators with parameters

User define iostream manipulators with parameters

Scheduled Pinned Locked Moved C / C++ / MFC
c++iosquestion
2 Posts 2 Posters 0 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.
  • O Offline
    O Offline
    oRion
    wrote on last edited by
    #1

    I have been trying to write a function in VC++ 6.0 on setting the setprecision and setw in a function. This is roughly how I intend to do .. my_set_function(int precision,int width) { setprecision(precision); setwidth(width); } fstream io("abc.dat",ios::out); . . double abc=1.234566,bcd=2.3456; . io << my_set_function(3,5) << abc << my_set_function(2,4) << bcd; Since I want to set it for every variable, I hope to do it in a neater and shorter manner.I know this code is not a functional one , hope someone have some idea of what I am trying to do? THanks a million! :omg:

    C 1 Reply Last reply
    0
    • O oRion

      I have been trying to write a function in VC++ 6.0 on setting the setprecision and setw in a function. This is roughly how I intend to do .. my_set_function(int precision,int width) { setprecision(precision); setwidth(width); } fstream io("abc.dat",ios::out); . . double abc=1.234566,bcd=2.3456; . io << my_set_function(3,5) << abc << my_set_function(2,4) << bcd; Since I want to set it for every variable, I hope to do it in a neater and shorter manner.I know this code is not a functional one , hope someone have some idea of what I am trying to do? THanks a million! :omg:

      C Offline
      C Offline
      Christian Graus
      wrote on last edited by
      #2

      If you want to write a manipulator that works for all types, including those that you did not define, then you'll need it to work in tandem with a stream of your own writing, which can very well be simply a stream that uses a normal stream, but applies your manipulator. Read my articles here on CP in the STL section for info on parameters in manipulators, and writing custom streams. Christian come on all you MS suckups, defend your sugar-daddy now. - Chris Losinger - 11/07/2002

      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