#include <iostream>
#include <fstream>
#include <string>
usingnamespace std
int main()
{
string line;
ifstream file("something.txt");
if(file.is_open())
{
while(file.good())
{
getline(file, line);
processLine(line); //this function we'll use to handle the specific line.
}
} else
cout << "Error opening file." << endl;
return 0;
}
From there i'd write a function to split a string, into a vector of its words. vector<string> splitString(string s);
so if we had the string "the quick brown fox," the function would find all the white spaces in the line (using string::find). You would find white spaces at indexes 3, 9, and 15. Then use string::substr to get substrings from 0-3, 3-9, 9-15, 15-std::string::npos. Put the results in a vector and return it.
void processLine(string s)
{
vector<string> words = splitString(s);
//So we know that the first word in the vector will be the operation.
if(words[0] == "CONVERT")
{
//do what you need to do to convert here
}
elseif(words[0] == "NOT")
{
//NOT logic here
}
elseif(words[0] == "AND")
{
//convert words[1], and words[2] into an integer value (perhaps using stringstream?)
int a, b;
cout << a & b << endl;
}
//and so on...
}