|
-
Sep 13th, 2002, 01:38 PM
#1
Thread Starter
Lively Member
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
-
Sep 14th, 2002, 07:28 AM
#2
Fanatic Member
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).
-
Sep 14th, 2002, 07:31 AM
#3
Monday Morning Lunatic
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
-
Sep 14th, 2002, 09:34 AM
#4
Thread Starter
Lively Member
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
-
Sep 14th, 2002, 09:37 AM
#5
Monday Morning Lunatic
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
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|