So, I created a function that reads a text file and saves, line by line, into a vector of strings by removing the commas.
The file entry is:
add $t2, $t3, $t4
sub $t5, $t6, $t7
addi $t6, $t7, 4
Applying the function:
void openFile(char** filePipe, std::vector<std::string> *lines){
std::ifstream filePine;
std::string line;
filePine.open(*filePipe);
if (!filePine.is_open()){
std::cout << "Arquivo " << *filePipe << " não foi encontrado" << std::endl;
}else{
std::cout << "Arquivo " << *filePipe << " foi encontrado" << std::endl;
std::cout << "Prosseguindo operação: " << std::endl;
while(!filePine.eof()){
getline(filePine, line);
//std::cout << line << std::endl;
line.erase(std::remove(line.begin(), line.end(),','), line.end());
lines->push_back(line);
}
}
filePine.close();
}
Generate this output:
add $t2 $t3 $t4
sub $t5 $t6 $t7
addi $t6 $t7 4
Now I need to separate each substring of this into 4 different vectors, all of them according to string0 (add, sub, addi, etc) since not all commands have 4 substrings (in this case I would add a nullptr to those that have less than four).
But I'm not finding something that will split this. can you help me?
Example: practical: In the entry:
add $t2 $t3 $t4
I need the program to store:
std::vector<std::string> instruc = add;
std::vector<std::string> op1 = $t2;
std::vector<std::string> op2 = $t3;
std::vector<std::string> op3 = $t4;
And so on successively for each input line, giving push_back () in the respective vector.