How can I access a character in the middle of a line in c++? -
i working on project consists of reading input file called input.txt has infinite number of lines. each line has roman numeral, space, plus or minus, space, , roman numeral. supposed add 2 numbers , write answer file called output.txt. however, can't think of way access operator. here sample input file:
xv + vii xii + viii
can give me idea of how can access plus sign each line of code?
if you're reading file standard input, can whitespace delimited tokens using extraction operator.
#include <string> #include <iostream> int main(int argc, char *argv[]) { std::string token; while (std::cin >> token) { // parse tokens here ... // example, i'll print out stream of tokens. std::cout << token << std::endl; } }
if you'd assume have 3 tokens per line, can this:
#include <string> #include <iostream> int main(int argc, char *argv[]) { std::string first, middle, last; while (std::cin >> first >> middle >> last) { // should print out operator std::cout << middle << std::endl; } }
Comments
Post a Comment