Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 3 of 3
  1. #1
    New Coder
    Join Date
    Feb 2014
    Posts
    11
    Thanks
    3
    Thanked 0 Times in 0 Posts

    Question Converting Strings to Dates

    Does someone have a quick code for converting strings to Dates in C++.

    Example: What is the date:
    User response: 12/05/14

    Can someone tell me a way I can code this to recognize it as a date, and make it so that the date is sortable? Not referring to the system date, but a user input date.

    Any help will be appreciated.

  • #2
    New Coder
    Join Date
    Feb 2014
    Posts
    11
    Thanks
    3
    Thanked 0 Times in 0 Posts
    Still looking for some assistance on this code.

  • #3
    New to the CF scene
    Join Date
    Feb 2014
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts
    One possible solution...

    Code:
    #include <iostream>
    
    void parseString(const std::string &input) {
        int month;
        int day;
        int year;
        if (std::sscanf(input.c_str(), "%d/%d/%d", &month, &day, &year) != 3)
        {
            // handle error
        } else
        {
            std::cout << month << std::endl << day << std::endl << year << std::endl;
        }
    }
    
    int main(void)
    {
        parseString("12/05/14");
        return 0;
    }


  •  

    Tags for this Thread

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •