The answers were great, maybe I redo my code. I ended up finishing it on the nail. But I liked knowing that I can "automate" this. I solved it this way:
#ifndef PACOTE_H
#define PACOTE_H
#include <vector>
#include <fstream>
#include <string>
class Pacote
{
public:
/*Metodo que retorna o nome do pacote definido pelo usuário*/
std::string GetnomeDoPacote(){
return nomeDoPacote;}
/*Metodo que define o nome do pacote a ser trabalhado*/
void SetnomeDoPacote(std::string variavelNomeDoPacote){
nomeDoPacote = variavelNomeDoPacote;}
/*Metodo que retorna as dependencias do pacote*/
std::vector<std::string> GetdependenciasDoPacote(){
return dependenciasDoPacote;}
/*Metodo que extrai as dependencias do pacote de um arquivo .txt linha a linha, para que elas sejam trabalhadas*/
void SetdependenciasDoPacote(std::string TXT){
std::string linha;
std::ifstream dependenciasTXT (TXT);
if (dependenciasTXT.is_open())
{
while ( getline(dependenciasTXT,linha) )
{
dependenciasDoPacote.push_back(linha);
}
/*O primeiro e o último elemento do arquivo .txt não nos enteressa, pois eles não contem o nome de
nenhuma dependencia a ser baixada*/
dependenciasDoPacote.erase(dependenciasDoPacote.begin());
dependenciasDoPacote.pop_back();
/*Para cada elemento adquirido através do comando 'apt-cache depends', temos as classificaçoes "Depende", "Recomendado" e "Sugere".
Precisamos remover essas strings do vector que armazenará essas dependências, logo, o esquema abaixo busca pelo primeiro elemento dessas
strings, afim de identifica-las e removêlas atráves do comando erase.*/
for(int linha = 0; linha < dependenciasDoPacote.size(); linha++){
for(int elementoDaLinha = 2; elementoDaLinha < sizeof(dependenciasDoPacote[linha]); elementoDaLinha++){
if(dependenciasDoPacote[linha][elementoDaLinha] == 'D'){
dependenciasDoPacote[linha].erase(dependenciasDoPacote[linha].begin(), dependenciasDoPacote[linha].begin()+10);
}
else
if(dependenciasDoPacote[linha][elementoDaLinha] == 'R'){
dependenciasDoPacote[linha].erase(dependenciasDoPacote[linha].begin(), dependenciasDoPacote[linha].begin()+12);
}
else
if(dependenciasDoPacote[linha][elementoDaLinha] == 'S'){
dependenciasDoPacote[linha].erase(dependenciasDoPacote[linha].begin(), dependenciasDoPacote[linha].begin()+9);
}
}
}
dependenciasTXT.close();
}
else{
dependenciasDoPacote.push_back("Não foi possível encontrar o arquivo de dependências! :(");
}
}
/*Metodo que retorna o nome do repositório PPA do pacote, definido pelo usuario*/
std::string GetrepositorioPPADoPacote(){
return repositorioPPADoPacote;}
/*Metodo que define o nome do repositório PPA a ser trabalhado*/
void SetrepositorioPPADoPacote(std::string nomeDoRepositorioPPA){
repositorioPPADoPacote = nomeDoRepositorioPPA; }
private:
std::string nomeDoPacote;
std::vector<std::string> dependenciasDoPacote;
std::string repositorioPPADoPacote;
};
#endif PACOTE_H
I used the Rase and Begin method. Okay, it wasn’t exactly on the nail, but it was almost on the nail.
dependencesDoPackage[line]. Rase(dependencesDoPackage[line]. Begin(), dependencesDoPackage[line]. Begin()+9);
With Rase I define that I want to erase, and with Begin I say that I want to erase by the front. I’m working with a vector. the vector line 0 has a certain amount of elements, and if I say 'dependencesDoPackage[line]. Begin(), I refer to the first element(element 0). In the above passage, I say I want to delete from element 0 to element 9.
dependencesDoPackage[line]. Rase(dependencesDoPackage[line]. Begin() /of element 0/, dependencesDoPackage[line]. Begin()+9 /to element 9/);
This works because the . txt file being worked on follows a pattern. It always starts at the [line][2] element of the vector. And it always starts either with Recommended, or with Depends, or with Suggests. So, I know, through ifs and elses what I’m deleting or not. If recommended, starting with the element [line][2] by the letter 'R', I delete until such element, if it is Suggest, starting with the letter’S', I delete until such element.... Anyway. Please point out errors or bad practices in my code.
THANK YOU!! VERY GOOD TOO!!!!!
– MiguelTeixeira