The answers were great, maybe I'd redo my code. I ended up finishing it on the same nail. But I enjoyed knowing that I can "automate" this. I solved it as follows:
#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 erase method and begin. Okay, it was not exactly on the nail, but it was almost on the nail.
(line dependencies) [line] .erase (package dependencies [line] .begin (), packet dependencies [line] .begin () + 9);
With the erase I define that I want to delete, and with the begin I say that I want to erase from the front. I am working with a vector. line 0 of the vector has a certain amount of elements, and if I say'Position dependencies [line] .begin (), I'm referring to the first element (element 0). In the above excerpt, I say that I want to delete element 0 through element 9.
DependenciesOfPacote [row] .erase (dependenciesDoPacote [line] .begin () / of element 0 /, dependenciesDoPacote [row] .begin () + 9 / to element 9 /);
This works because the .txt file being worked follows a pattern. It always begins in the vector element [line] [2]. And 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 it is recommended, which starts with the element [line] [2] by the letter 'R', I delete that element, if it suggests, which starts with the letter 'S', I delete that element .... Anyway. Please point out errors or bad practices in my code.