String Conversions

This is a discussion on String Conversions within the C++ Programming forums, part of the General Programming Boards category; Hai guys, I have to enter a file name from the command prompt. So this file name will go into ...

  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 wrongness Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    32,418
    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.
    I support http://www.ukip.org/ as the first necessary step to a free Europe.

  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, 02:23 PM
  5. creating class, and linking files
    By JCK in forum C++ Programming
    Replies: 12
    Last Post: 12-08-2002, 01:45 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21