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. How to get rid of this ERROR

How to get rid of this ERROR

Scheduled Pinned Locked Moved C / C++ / MFC
helpiostutorial
13 Posts 5 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 pl_kode

    This is what I am doin... string filename; //filename contains "c:\\new folder\\file1.txt" .... .... ofstream myfile; myfile.open (filename, ios::app); When I compile or built this I get error C2664: 'void __thiscall std::basic_ofstream >::open(const char *,int)' : cannot convert parameter 1 from 'class std::basic_stringaits,class std::allocator >' to 'const char *' No user-defined-conversion operator available that can perform this conversion, or the operator cannot be called Error executing cl.exe. Please help me get rid of this or any suggestion to make changes to this. THANKS

    M Offline
    M Offline
    Maximilien
    wrote on last edited by
    #4

    pl_kode wrote:

    myfile.open (filename, ios::app);

    does replacing it with something like : myfile.open (filename.c_str(), ios::app); works ?

    Maximilien Lincourt Your Head A Splode - Strong Bad

    P 1 Reply Last reply
    0
    • M Maximilien

      pl_kode wrote:

      myfile.open (filename, ios::app);

      does replacing it with something like : myfile.open (filename.c_str(), ios::app); works ?

      Maximilien Lincourt Your Head A Splode - Strong Bad

      P Offline
      P Offline
      pl_kode
      wrote on last edited by
      #5

      It doesn't show any errors like this. But it also do not create a file in the folder.

      C 1 Reply Last reply
      0
      • P pl_kode

        Thanks a lot. It worked.

        P Offline
        P Offline
        pl_kode
        wrote on last edited by
        #6

        It does not show any error like this.. Nor does its creating any file in the specified path. Wt shud I do.

        R C 2 Replies Last reply
        0
        • P pl_kode

          It does not show any error like this.. Nor does its creating any file in the specified path. Wt shud I do.

          R Offline
          R Offline
          Rajkumar R
          wrote on last edited by
          #7

          pl_kode wrote:

          filename contains "c:\\new folder\\file1.txt"

          did you created the "new folder" directory in "C:\" drive, you should not expect open API will do that.

          1 Reply Last reply
          0
          • P pl_kode

            It does not show any error like this.. Nor does its creating any file in the specified path. Wt shud I do.

            C Offline
            C Offline
            CPallini
            wrote on last edited by
            #8

            for istance, you may call myfile.rdstate().

            If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler. -- Alfonso the Wise, 13th Century King of Castile.
            This is going on my arrogant assumptions. You may have a superb reason why I'm completely wrong. -- Iain Clarke

            P 1 Reply Last reply
            0
            • P pl_kode

              It doesn't show any errors like this. But it also do not create a file in the folder.

              C Offline
              C Offline
              cagespear
              wrote on last edited by
              #9

              Can you try creating a file manually there ? Do you have the write access to the path?

              P 1 Reply Last reply
              0
              • C cagespear

                Can you try creating a file manually there ? Do you have the write access to the path?

                P Offline
                P Offline
                pl_kode
                wrote on last edited by
                #10

                Yes if i give .. ofstream myfile; myfile.open ("c:\\New folder\\file1.txt", ios::app); It works. Even a file is created. But I want it the other way.

                R 1 Reply Last reply
                0
                • C CPallini

                  for istance, you may call myfile.rdstate().

                  If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler. -- Alfonso the Wise, 13th Century King of Castile.
                  This is going on my arrogant assumptions. You may have a superb reason why I'm completely wrong. -- Iain Clarke

                  P Offline
                  P Offline
                  pl_kode
                  wrote on last edited by
                  #11

                  I tried it by using rdstate(). Still stuck with the same thing.

                  C 1 Reply Last reply
                  0
                  • P pl_kode

                    Yes if i give .. ofstream myfile; myfile.open ("c:\\New folder\\file1.txt", ios::app); It works. Even a file is created. But I want it the other way.

                    R Offline
                    R Offline
                    Rajkumar R
                    wrote on last edited by
                    #12

                    can you post how you initialise filename variable. or check the value of filename before open(),

                    cout << filename.c_str();

                    1 Reply Last reply
                    0
                    • P pl_kode

                      I tried it by using rdstate(). Still stuck with the same thing.

                      C Offline
                      C Offline
                      CPallini
                      wrote on last edited by
                      #13

                      pl_kode wrote:

                      I tried it by using rdstate()

                      What is the return value? Have you read the Rajkumar reply? :)

                      If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler. -- Alfonso the Wise, 13th Century King of Castile.
                      This is going on my arrogant assumptions. You may have a superb reason why I'm completely wrong. -- Iain Clarke

                      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