-
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
-
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).
-
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 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
-
For efficiency, try:
Code:
string str(argv[1]);
;)
Just make sure there are enough args though ;)