File input and Arrays

I have to read data from a file in columns like this:

NOT 11010111
AND 10110010 11001110
OR 11011001 11100101
CONVERT 10011010
LSHIFT 11011101 3

I know how to read data from a file, however, I don't know how to read it in the column form while keeping everything separate. Each column must be stored as arrays so they can be modified(Array 1, Array 2, Array 3). I understand(most) of the modification process, just not how to store all of this data in arrays. They should all be stored as strings.

Any help, tips, links would be appreciated!
you need 3 labels:
char* oper, arg1, arg2

Read in the oper, and determine how many arguments to read after that (1 or 2)
read the argument, then convert it from char* to an int by parsing each 1 and 0 (or in the case of LSHIFT, just copy it over). Then perform the operation requested.
You could read all three arguments as std::strings.
Then use something like this for binary numbers
1
2
    char **ptr = 0;
    long num1 = strtol(second.c_str(), ptr, 2);

or this for decimal integers
 
    long num2 = atol(third.c_str());

http://www.cplusplus.com/reference/clibrary/cstdlib/strtol/
http://www.cplusplus.com/reference/clibrary/cstdlib/atol/
Last edited on
Topic archived. No new replies allowed.