1

I am designing a chess game using the UCI Protocol. The program requires line commands as input.

My question is if I need a function separate from the main() function for parsing these commands, and also how to I get the input for parsing? I realize that char* argv is named in the function parameter, but I found that using argv = cin.get() didn't work.

I have looked at many tutorials and none of them answer either question.

Also I'm sorry if this is badly worded.

  • 3
    [Start with a C++ book](http://stackoverflow.com/questions/388242/the-definitive-c-book-guide-and-list) and learn the syntax before attempting to use libraries and making a game. – AJG85 Jun 05 '12 at 23:32
  • I'm trying to learn the syntax now. I also have had success in the past with games such as pac-man. –  Jun 05 '12 at 23:33
  • @Redmastif There's much much more to C++ than _syntax_. No Whammy! No Whammy! No Whammy! – Captain Obvlious Jun 05 '12 at 23:39
  • @ChetSimpson Of course there is. I was replying to AJG85 and his comment on me needing to learn syntax. Which I'm doing. –  Jun 05 '12 at 23:44
  • Yup my bad, I shouldn't have said learn the syntax when I meant learn the language. You seemed to be a tad confused on the purpose of functions and how to make them and `argv = cin.get()` kind of trips off some major whammies ;-) – AJG85 Jun 05 '12 at 23:45
  • @AJG85 Yes that is a fair assessment. If I were old enough to have a better paying job I would buy a book for myself. Until then, however, I have to suffice with internet tutorials. –  Jun 05 '12 at 23:54
  • 1
    @Redmastif Ah I see, in that case check out http://www.cplusplus.com it's a decent reference. There is also plenty of info on MSDN. [Qt](http://qt.nokia.com/products/) is a cross-platform C++ framework that comes with an IDE and really good documentation as well ... all the above are free. – AJG85 Jun 06 '12 at 00:04
  • [StackOverflow is not a C++ Tutorial](http://meta.stackexchange.com/a/134609/142865) – John Dibling Jun 06 '12 at 01:36
  • @JohnDibling I know. I came here because tutorials were being of no help to me. –  Jun 06 '12 at 01:50

1 Answers1

3

May I suggest non mythical programming:

#include <string>
#include <vector>

int main(int argc, char**argv)
{
    const std::vector<std::string> args(argv, argv+argc);

    // be merry and use `args`

}

Update Hmm. I guess you meant console/standard input. In that case, a read loop might be what you want:

std::string line;
while (std::getline(std::cin, line))
{
     // process command in line
}
sehe
  • 374,641
  • 47
  • 450
  • 633
  • 1
    Might want to use `argv+1` starting point to skip the program path and executable name and just get the command line args in the vector ... – AJG85 Jun 05 '12 at 23:42