Thread: String Conversions

  1. #1
    Registered User
    Join Date
    Sep 2001
    Posts
    2

    String Conversions

    Hai guys,
    I have to enter a file name from the command prompt. So this file name will go into the program as a string. Now, how can I convert this string into a filename, so that my program will understand that it will have to read from the file name that has been entered on the command line?
    eg:
    ..\debug>program.exe file.txt
    Thanks Guys.
    -Vijay

  2. #2
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,656
    Code:
    int main ( int argc, char *argv[] ) {
        // filename is in the string which is argv[1]
    }
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.

  3. #3
    Registered User
    Join Date
    Sep 2001
    Posts
    2

    More Information

    Hai Salem,
    Perhaps it would be interesting to know a new piece of Information. The string that gets read in is just a string. This string needs to be converted into a char *[]. So we should use

    string tempFileName = argv[1];
    string fileName = tempFileName.c_str();

    So this fileName is the one that we should be interested in.

    Thanks for your reply though. I just found out this info from my super.

    -Vijay

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. char Handling, probably typical newbie stuff
    By Neolyth in forum C Programming
    Replies: 16
    Last Post: 06-21-2009, 04:05 AM
  2. String Class
    By BKurosawa in forum C++ Programming
    Replies: 117
    Last Post: 08-09-2007, 01:02 AM
  3. RicBot
    By John_ in forum C++ Programming
    Replies: 8
    Last Post: 06-13-2006, 06:52 PM
  4. Classes inheretance problem...
    By NANO in forum C++ Programming
    Replies: 12
    Last Post: 12-09-2002, 03:23 PM
  5. creating class, and linking files
    By JCK in forum C++ Programming
    Replies: 12
    Last Post: 12-08-2002, 02:45 PM