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. Renaming a file

Renaming a file

Scheduled Pinned Locked Moved C / C++ / MFC
helpquestion
5 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
    pl_kode
    wrote on last edited by
    #1

    I have two strings and I do the following...

    string old_path; // this is like C:\\folder\\file.txt
    string new_path; // this is like C:\\folder\\file1.txt

    rename(old_path_newpath)

    Doing this I get the following error. How do I overcome this error.

    error C2664: 'rename' : cannot convert parameter 1 from 'class std::basic_string,class std::allocator >' to 'const char *'
    No user-defined-conversion operator available that can perform this conversion, or the operator cannot be called

    THANKS

    G H 2 Replies Last reply
    0
    • P pl_kode

      I have two strings and I do the following...

      string old_path; // this is like C:\\folder\\file.txt
      string new_path; // this is like C:\\folder\\file1.txt

      rename(old_path_newpath)

      Doing this I get the following error. How do I overcome this error.

      error C2664: 'rename' : cannot convert parameter 1 from 'class std::basic_string,class std::allocator >' to 'const char *'
      No user-defined-conversion operator available that can perform this conversion, or the operator cannot be called

      THANKS

      G Offline
      G Offline
      Garth J Lancaster
      wrote on last edited by
      #2

      try :- rename(old_path.c_str(), new_path.c_str() ); notice the c_str() - that effectively gives you a const char * from the string Im presuming rename(old_path_newpath) was a typo .. 'g'

      1 Reply Last reply
      0
      • P pl_kode

        I have two strings and I do the following...

        string old_path; // this is like C:\\folder\\file.txt
        string new_path; // this is like C:\\folder\\file1.txt

        rename(old_path_newpath)

        Doing this I get the following error. How do I overcome this error.

        error C2664: 'rename' : cannot convert parameter 1 from 'class std::basic_string,class std::allocator >' to 'const char *'
        No user-defined-conversion operator available that can perform this conversion, or the operator cannot be called

        THANKS

        H Offline
        H Offline
        Hamid Taebi
        wrote on last edited by
        #3

        Except this error you can use of SHFileOperation instead rename.

        G 1 Reply Last reply
        0
        • H Hamid Taebi

          Except this error you can use of SHFileOperation instead rename.

          G Offline
          G Offline
          Garth J Lancaster
          wrote on last edited by
          #4

          if he cant figure out how to use a relatively simple API like rename(), do you honestly think he's going to be able to figure out SHFileOperation ? I dont think so ... (even I use a wrapper class around SHFileOperation to make it simpler) 'g'

          H 1 Reply Last reply
          0
          • G Garth J Lancaster

            if he cant figure out how to use a relatively simple API like rename(), do you honestly think he's going to be able to figure out SHFileOperation ? I dont think so ... (even I use a wrapper class around SHFileOperation to make it simpler) 'g'

            H Offline
            H Offline
            Hamid Taebi
            wrote on last edited by
            #5

            No my answer was genraly SHFileOperation is better than rename not for solve problem.

            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