R
Roberto Dias
Hi,
I've got a text file and I need to capture some data in it. I
implemented ( using comp.lang.c++ help) a typical searching algorithm
that first find the header (label that identifies the data inside the
text file) of the interested data, giving me a pair row-column and now
I need to jump some lines foward for getting the data. I'm so shine
about that, but I simply cannot do this last thing! I've trying,
without no success, to "getline" to a temporary file for creating a
big "char" matix and after use the pair row-column to identifies and
get the data, but this is so much complex to a simple thing.
Here are my code:
#include<iostream>
using std::cout;
using std::cin;
using std::endl;
#include<fstream>
using std::ios;
using std::ifstream;
using std:fstream;
#include<string>
using std::string;
void coletaDadosSimulacaoDinamica(void);
int main()
{
// Limpeza da tela
system("cls");
coletaDadosSimulacaoDinamica();
return 0;
}
void coletaDadosSimulacaoDinamica(void)
{
string nomeArquivoStb, stringLinhaCopiada, consulta = "DSIM";
string::size_type posicao(0);
const string::size_type tamanho(consulta.size());
char arrayLinhaCopiada[255];
int contadorLinha = 0;
cout << "Entre o arquivo .stb: ";
cin >> nomeArquivoStb;
cout << endl;
ifstream objetoArquivoStb(nomeArquivoStb.c_str());
while (objetoArquivoStb.getline(arrayLinhaCopiada, 255))
{
stringLinhaCopiada = arrayLinhaCopiada;
if (stringLinhaCopiada.find(consulta) != string::npos)
{
while((posicao = stringLinhaCopiada.find(consulta, posicao)) !=
string::npos)
{
// Imprime na tela o numero da linha da ocorrencia
cout << "Substring encontrado na linha " << (contadorLinha +
1);
cout << ", coluna " << (posicao + 1) << endl;
cout << endl;
// Incremento da posicao
posicao += tamanho;
}
}
//objetoArquivoAux << stringLinhaCopiada;
// Contador de linhas
contadorLinha++;
}
}
Unfortunately the comments are in Portuguese language.
Can we change some ideas?
Thanks a lot,
Roberto Dias
I've got a text file and I need to capture some data in it. I
implemented ( using comp.lang.c++ help) a typical searching algorithm
that first find the header (label that identifies the data inside the
text file) of the interested data, giving me a pair row-column and now
I need to jump some lines foward for getting the data. I'm so shine
about that, but I simply cannot do this last thing! I've trying,
without no success, to "getline" to a temporary file for creating a
big "char" matix and after use the pair row-column to identifies and
get the data, but this is so much complex to a simple thing.
Here are my code:
#include<iostream>
using std::cout;
using std::cin;
using std::endl;
#include<fstream>
using std::ios;
using std::ifstream;
using std:fstream;
#include<string>
using std::string;
void coletaDadosSimulacaoDinamica(void);
int main()
{
// Limpeza da tela
system("cls");
coletaDadosSimulacaoDinamica();
return 0;
}
void coletaDadosSimulacaoDinamica(void)
{
string nomeArquivoStb, stringLinhaCopiada, consulta = "DSIM";
string::size_type posicao(0);
const string::size_type tamanho(consulta.size());
char arrayLinhaCopiada[255];
int contadorLinha = 0;
cout << "Entre o arquivo .stb: ";
cin >> nomeArquivoStb;
cout << endl;
ifstream objetoArquivoStb(nomeArquivoStb.c_str());
while (objetoArquivoStb.getline(arrayLinhaCopiada, 255))
{
stringLinhaCopiada = arrayLinhaCopiada;
if (stringLinhaCopiada.find(consulta) != string::npos)
{
while((posicao = stringLinhaCopiada.find(consulta, posicao)) !=
string::npos)
{
// Imprime na tela o numero da linha da ocorrencia
cout << "Substring encontrado na linha " << (contadorLinha +
1);
cout << ", coluna " << (posicao + 1) << endl;
cout << endl;
// Incremento da posicao
posicao += tamanho;
}
}
//objetoArquivoAux << stringLinhaCopiada;
// Contador de linhas
contadorLinha++;
}
}
Unfortunately the comments are in Portuguese language.
Can we change some ideas?
Thanks a lot,
Roberto Dias