In a broader scope my problem is that I need to use input from the command line (as opposed to using cin) to determine the action of an if statement.
For example, if(operation == a). How can i set up the variable "operation" so that it gets assigned to an argument from the command line? Simply writing
operation = argv[1] won't work, so how do you do it? or do i have the total wrong idea?
I've been scouring the web all night but being fairly new to C++ i'm sure i'm using an incorrect term or something and as of yet haven't been able to find a plainly written solution/explanation.
You can directly use argv[1] instead of the variable operation.
A simplest way is to declare variable operation as having type std::string. For example
You are overlooking the fact that argv[] is an array. Each element of that array is pointer to a character string. That's why its type is given as char *.
That's why the previous suggestion was to use type std::string rather than type char.
You could do everything using the older c-strings but then you need to get involved with extra work, such as strcpy() to copy, or strcmp() to compare and so on.
The std::string allows copying one string to another with a simple = operator: