Tuesday, December 22, 2015

Crude way to use command line arguments

I had people tell me this is not the right way to use command line arguements but it works. There's a lot of really good ways to parse command line arguments. And there are a lot better ways than this. But if you're lazy.

#include <iostream>
#include <cstring>
using namespace std;

int main(int argc,char* argv[])
{

std::string str=(argv[1]);

for(std::string::size_type i = 0; i < str.size(); ++i) {
    str(str[i]) << endl;

}

    if (str =="donkey")
    {
    cout << "punch"<< endl;

    } else cout << "kick" << endl;
    return 0;
}

No comments:

Post a Comment