Here’s an excerpt of the code.
int main(int argc, char*argv[])
string s;
if (argc == 2)
argv[1] == s; //I tried this with and without brackets
else if (argc == 1){
cout << "Enter a number." << endl;
cin >> s;
}
else
{
cout << "Use only one argument" << endl;
}
cout << s << endl;
However, if there’s an argument (first condition) then it’s ALWAYS 0. Anyone know why?
This line
should be
Your current code compares
argv[1]to an empty string using==, and discards the result of comparison. It looks like you are after getting the first argument into the strings, so you need an assignment.