Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. how to solve the problem about:cannot convert 'std::string {aka std::basic_string<char>}' to 'const char*' for argument '1' to 'char* strptime(const char*, const char*, tm*)'
Forum Update on Monday, May 27th 2025

how to solve the problem about:cannot convert 'std::string {aka std::basic_string<char>}' to 'const char*' for argument '1' to 'char* strptime(const char*, const char*, tm*)'

Scheduled Pinned Locked Moved Solved General and Desktop
8 Posts 3 Posters 3.8k Views
  • 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.
  • L Offline
    L Offline
    Lian ZhiYang
    wrote on 27 Feb 2021, 15:00 last edited by
    #1

    I wrote the strptime function in Windows 10 environment to convert a string to a time,but when I build the code ,there is the problem:cannot convert 'std::string {aka std::basic_string<char>}' to 'const char*' for argument '1' to 'char* strptime(const char*, const char*, tm*)'.How to solve the problem?Thank you!

    J 1 Reply Last reply 27 Feb 2021, 15:37
    0
    • L Lian ZhiYang
      27 Feb 2021, 15:00

      I wrote the strptime function in Windows 10 environment to convert a string to a time,but when I build the code ,there is the problem:cannot convert 'std::string {aka std::basic_string<char>}' to 'const char*' for argument '1' to 'char* strptime(const char*, const char*, tm*)'.How to solve the problem?Thank you!

      J Offline
      J Offline
      JohnM64
      wrote on 27 Feb 2021, 15:37 last edited by
      #2

      @Lian-ZhiYang have you tried using the std::string c_str() method to convert std::string to const char*?
      See here.

      1 Reply Last reply
      1
      • L Offline
        L Offline
        Lian ZhiYang
        wrote on 27 Feb 2021, 16:04 last edited by
        #3

        yes,I have tried the method

        J 1 Reply Last reply 27 Feb 2021, 16:06
        0
        • L Lian ZhiYang
          27 Feb 2021, 16:04

          yes,I have tried the method

          J Offline
          J Offline
          JohnM64
          wrote on 27 Feb 2021, 16:06 last edited by
          #4

          @Lian-ZhiYang Can you show a few lines of your code?

          1 Reply Last reply
          0
          • L Offline
            L Offline
            Lian ZhiYang
            wrote on 27 Feb 2021, 16:25 last edited by
            #5

            a688f97f-f792-4313-836e-c4966f1e7d9d-image.png

            J 1 Reply Last reply 27 Feb 2021, 16:34
            0
            • L Lian ZhiYang
              27 Feb 2021, 16:25

              a688f97f-f792-4313-836e-c4966f1e7d9d-image.png

              J Offline
              J Offline
              JohnM64
              wrote on 27 Feb 2021, 16:34 last edited by
              #6

              @Lian-ZhiYang it looks like you've fixed the error in the 2nd strptime() by using c_str() (line 86), but not in the 1st (line 77). You need to use c_str() in line 77 as well.

              1 Reply Last reply
              1
              • L Offline
                L Offline
                Lian ZhiYang
                wrote on 27 Feb 2021, 16:51 last edited by
                #7

                Thank you very much! I have solved my problem by your way!

                1 Reply Last reply
                0
                • C Online
                  C Online
                  Christian Ehrlicher
                  Lifetime Qt Champion
                  wrote on 27 Feb 2021, 19:11 last edited by
                  #8

                  Why not use QDateTime (when you already ask a c++ only question in a Qt forum ;) )

                  Qt Online Installer direct download: https://download.qt.io/official_releases/online_installers/
                  Visit the Qt Academy at https://academy.qt.io/catalog

                  1 Reply Last reply
                  0

                  1/8

                  27 Feb 2021, 15:00

                  • Login

                  • Login or register to search.
                  1 out of 8
                  • First post
                    1/8
                    Last post
                  0
                  • Categories
                  • Recent
                  • Tags
                  • Popular
                  • Users
                  • Groups
                  • Search
                  • Get Qt Extensions
                  • Unsolved