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. CString parsing

CString parsing

Scheduled Pinned Locked Moved C / C++ / MFC
c++jsonhelp
3 Posts 3 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.
  • P Offline
    P Offline
    poserGeek
    wrote on last edited by
    #1

    Hey all I need some "C++ 101" help, I am working on a function that reads in a string and converts it into a CTime, using atoi( ):confused:. The function declaration is bool ConvertTimeStr(const CString& TimeStr, CTime& Dest) any suggestions on how I can convert a string such as "12:00:00" into 12:00:00

    N R 2 Replies Last reply
    0
    • P poserGeek

      Hey all I need some "C++ 101" help, I am working on a function that reads in a string and converts it into a CTime, using atoi( ):confused:. The function declaration is bool ConvertTimeStr(const CString& TimeStr, CTime& Dest) any suggestions on how I can convert a string such as "12:00:00" into 12:00:00

      N Offline
      N Offline
      Nick Parker
      wrote on last edited by
      #2

      GRAMI04 wrote: any suggestions on how I can convert a string such as "12:00:00" into 12:00:00 Read this: Date and Time in C++[^] :) -Nick Parker

      1 Reply Last reply
      0
      • P poserGeek

        Hey all I need some "C++ 101" help, I am working on a function that reads in a string and converts it into a CTime, using atoi( ):confused:. The function declaration is bool ConvertTimeStr(const CString& TimeStr, CTime& Dest) any suggestions on how I can convert a string such as "12:00:00" into 12:00:00

        R Offline
        R Offline
        Rob Groves
        wrote on last edited by
        #3

        The quoted article will help I'm sure, but I have found the following 2 approaches to be useful, alone or in combination. 1) The MFC COleDateTime class provides some string parsing capabilities, and you can then check the GetStatus() return code. 2) Alternatively, you could try something like: bool ConvertTimeStr(const CString& TimeStr, CTime& Dest) { int hh, mi, ss; char ch; // ch catches junk beyond end of string if (sscanf(TimeStr, "%d:%d:%d%c", &hh, &mi, &ss, &ch) != 3) return false // now check for valid days of month etc. // The MFC classes can be used to do this. return whatever!! }

        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