Thread: New to C++ problem saving files

  1. #1
    Registered User
    Join Date
    Nov 2005
    Posts
    2

    New to C++ problem saving files

    Hello,
    I am new to C programming and I am having an issue that I can't seem to figure out. I would greatly appreciate anyone's help!

    I am making a very simple program that takes some user input and saves it to a file. This is a console application. Getting the core information from the user and storing it into a file is working correctly. I am creating a folder and saving the file into the folder. This is working correctly as well. The problem is that I need to have the user rename the folder and the file. To get the user input I am using cin. I store the user's input into a variable and then write the user input to the file using:
    outfile<<myvariable<<endl;
    where outfile is my instance of ofstream.
    To rename the file and folder, I used the rename() function. This works as long as I hardcode the values. I know that rename() accepts to params that are typed const char*. When I try to place a variable for the 2nd param to rename(), I get an error of:
    invalid conversion of string to const char
    How can I use a variable to rename the file and folder that my program creates. I have been searching the internet and reference books and can't seem to find an answer. I tried to cast the type and this didn't work and I know that its not good practice.

    Can anyone please help!

    Thanks,

    Wes

  2. #2
    Registered User
    Join Date
    Aug 2005
    Posts
    1,267
    sounds like you are using std::string as one of the parameters. Use its c_str() method to convert to const char*.

  3. #3
    Registered User
    Join Date
    Nov 2005
    Posts
    2

    Thanks!!

    Great! that worked


    Thanks a lot!!!

    Wes

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Problem reading tiff image files?
    By compz in forum C++ Programming
    Replies: 9
    Last Post: 10-30-2009, 04:17 AM
  2. Problem with reading files
    By glopv2 in forum C Programming
    Replies: 3
    Last Post: 07-31-2007, 11:05 PM
  3. A question related to strcmp
    By meili100 in forum C++ Programming
    Replies: 6
    Last Post: 07-07-2007, 02:51 PM
  4. problem with text files
    By Gather in forum C++ Programming
    Replies: 27
    Last Post: 06-05-2006, 04:16 PM
  5. Saving files
    By GaPe in forum C Programming
    Replies: 6
    Last Post: 05-25-2002, 10:13 AM