I’ve been trying to run a program that will invert the order of a string and to run it, I have to type a second argument in prompt.
int main(int argc, char* argv[])
{
string text = argv[2];
for (int num=text.size(); num>0; num--)
{
cout << text.at(num);
}
return 0;
}
e.g. ./program lorem result: merol
You missed the includes and used
string::atwrong. There aresize()chars in the string but you start counting at 0. Then the loop has to run until num >= 0 and not num > 0. You also used the wrong index intoargv.This would still be an abomination of C++. A clearer way would be: