Results 1 to 5 of 5

Thread: argv[1] to normal string

  1. #1

    Thread Starter
    Lively Member
    Join Date
    Feb 2002
    Posts
    69

    argv[1] to normal string

    If the user starts my application with:
    application argument , then argv[1] will contain the argument,am I right?I need to convert argv[1] to a normal string,so that I can use it in the program,does anyone know how I can do this?
    thanks in advance for any help

  2. #2
    Fanatic Member riis's Avatar
    Join Date
    Nov 2001
    Posts
    551
    As far as I know argv[1] is a normal string (as is any argv[n]).
    You can do strlen, atof, whatever with it, but maybe not operations like strcat or strcpy(argv[1], blah) (although I haven't tested it).

  3. #3
    Monday Morning Lunatic parksie's Avatar
    Join Date
    Mar 2000
    Location
    Mashin' on the motorway
    Posts
    8,169
    The incoming argv pointer should technically be a const, although you can get away with changing it on some systems.

    Moral of the story: Don't.
    I refuse to tie my hands behind my back and hear somebody say "Bend Over, Boy, Because You Have It Coming To You".
    -- Linus Torvalds

  4. #4

    Thread Starter
    Lively Member
    Join Date
    Feb 2002
    Posts
    69
    I just did string str;str=string(argv[1]); and it works fine,so now I can do all the string stuff with it and change it What a bliss

  5. #5
    Monday Morning Lunatic parksie's Avatar
    Join Date
    Mar 2000
    Location
    Mashin' on the motorway
    Posts
    8,169
    For efficiency, try:
    Code:
    string str(argv[1]);


    Just make sure there are enough args though
    I refuse to tie my hands behind my back and hear somebody say "Bend Over, Boy, Because You Have It Coming To You".
    -- Linus Torvalds

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width