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. ATL / WTL / STL
  4. stl and sprints/sscans

stl and sprints/sscans

Scheduled Pinned Locked Moved ATL / WTL / STL
c++jsonhelptutorialannouncement
4 Posts 3 Posters 13 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.
  • I Offline
    I Offline
    Iccle
    wrote on last edited by
    #1

    Im trying to program an STL version of sprints and sscans using stl strings to format a variable number of arguments and print to or read from a string, but have become hopelessly lost in format flags/precisions etc. Function headers i would like to expose are: int SPrintS( std::string buffer, const std::string format, ...); ... and ...:confused: int SScanS( std::string buffer, const std::string format, ...); Both functions return the number of chars read/written to the string or -1 on conversion failure. In the implementation of these functions i dont want to call the c version of sprints or sscans (or svprintf etc). I understand how to deal with variable arguments, the problem im having is in parsing the format specifier, it takes the general form: %[flags] [width] [.precision] [{h | l | I64 | L}]type My attempts at a parse function always seems to become unruly then break down before it can cope with the complete range of optional prefixes to a type (those within [] ), that coupled with format strings can contain any number of format specifiers. Any suggstions as to the way forward would be welcomed.

    A L 2 Replies Last reply
    0
    • I Iccle

      Im trying to program an STL version of sprints and sscans using stl strings to format a variable number of arguments and print to or read from a string, but have become hopelessly lost in format flags/precisions etc. Function headers i would like to expose are: int SPrintS( std::string buffer, const std::string format, ...); ... and ...:confused: int SScanS( std::string buffer, const std::string format, ...); Both functions return the number of chars read/written to the string or -1 on conversion failure. In the implementation of these functions i dont want to call the c version of sprints or sscans (or svprintf etc). I understand how to deal with variable arguments, the problem im having is in parsing the format specifier, it takes the general form: %[flags] [width] [.precision] [{h | l | I64 | L}]type My attempts at a parse function always seems to become unruly then break down before it can cope with the complete range of optional prefixes to a type (those within [] ), that coupled with format strings can contain any number of format specifiers. Any suggstions as to the way forward would be welcomed.

      A Offline
      A Offline
      Anonymous
      wrote on last edited by
      #2

      Easiest route is to take a look at the GNU source code for sprintf and see how theyve done it!

      1 Reply Last reply
      0
      • I Iccle

        Im trying to program an STL version of sprints and sscans using stl strings to format a variable number of arguments and print to or read from a string, but have become hopelessly lost in format flags/precisions etc. Function headers i would like to expose are: int SPrintS( std::string buffer, const std::string format, ...); ... and ...:confused: int SScanS( std::string buffer, const std::string format, ...); Both functions return the number of chars read/written to the string or -1 on conversion failure. In the implementation of these functions i dont want to call the c version of sprints or sscans (or svprintf etc). I understand how to deal with variable arguments, the problem im having is in parsing the format specifier, it takes the general form: %[flags] [width] [.precision] [{h | l | I64 | L}]type My attempts at a parse function always seems to become unruly then break down before it can cope with the complete range of optional prefixes to a type (those within [] ), that coupled with format strings can contain any number of format specifiers. Any suggstions as to the way forward would be welcomed.

        L Offline
        L Offline
        Li Lirong
        wrote on last edited by
        #3

        Hi, There is an article by Sutter on this issue. If you are interested, you can read it here: http://www.gotw.ca/publications/mill19.htm Also, there is an experimental c++ string format library (It is accepted by the boost organizers) : http://groups.yahoo.com/group/boost/files/format2/ Regards, Lirong

        I 1 Reply Last reply
        0
        • L Li Lirong

          Hi, There is an article by Sutter on this issue. If you are interested, you can read it here: http://www.gotw.ca/publications/mill19.htm Also, there is an experimental c++ string format library (It is accepted by the boost organizers) : http://groups.yahoo.com/group/boost/files/format2/ Regards, Lirong

          I Offline
          I Offline
          Iccle
          wrote on last edited by
          #4

          thanks guys :)

          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