0
So I created a function that reads a text file and stores, line by line, in a string array by removing 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();
}
Generates me 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.) because not all commands have 4 substrings (in case I would add a nullptr in those that have less than four).
Only I’m not finding something that serves as a split for it. Could you help me?
Example: practical: practical: At the entrance:
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 successively for each input line, giving push_back() on the respective vector.