I’m constructing a line command based chess engine. When a command is given to the engine (as a string), I have a couple of regex expressions run to determine if the command is valid. If it’s valid, then the command is passed on to be parsed.
When a command such as a6a4 is given to the engine in string input;, is it valid to use a command like:
istringstream (input.at(1)) >> originalx; or:
istringstream buffer(input.at(1)); buffer >> originalx;
to convert just the part of the string with the integer into an actual int? I have been trying these methods of conversion, all using str.at(x) rather than just str and none of them seem to be working.
I know this may seem like a duplicate question because everyone wants to know how to convert an entire string to an int, but what about just a specific part of a string? I did search Google for answers as well but nothing I found was helpful.
A specific part of a
stringis still astring. You can just dostr.substr(1, 1)and convert that whole sub-string to anint.