file processing

Discussion in 'C++' started by Roberto Dias, Jun 28, 2004.

  1. Roberto Dias

    Roberto Dias Guest

    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::eek: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
    Roberto Dias, Jun 28, 2004
    #1
    1. Advertising

  2. Roberto Dias

    David Harmon Guest

    On 27 Jun 2004 16:04:02 -0700 in comp.lang.c++,
    (Roberto Dias) wrote,
    > ifstream objetoArquivoStb(nomeArquivoStb.c_str());
    >
    > while (objetoArquivoStb.getline(arrayLinhaCopiada, 255))
    > {
    > stringLinhaCopiada = arrayLinhaCopiada;
    >
    > if (stringLinhaCopiada.find(consulta) != string::npos)
    > {


    // add:
    posicao = 0;

    > while((posicao = stringLinhaCopiada.find(consulta, posicao)) !=
    >string::npos)


    For the first line from the file, posicao is 0 and all is good.
    For the remaining lines, posicao is stuck at npos and find() will fail.
    David Harmon, Jun 28, 2004
    #2
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Andy
    Replies:
    1
    Views:
    1,363
    J├╝rgen Exner
    Jan 20, 2004
  2. Maxim
    Replies:
    0
    Views:
    389
    Maxim
    Jul 7, 2003
  3. Long Le
    Replies:
    3
    Views:
    1,156
    Long Le
    Aug 11, 2004
  4. MWells
    Replies:
    2
    Views:
    402
    MWells
    Jan 11, 2005
  5. Hubert Hung-Hsien Chang
    Replies:
    2
    Views:
    403
    Michael Foord
    Sep 17, 2004
Loading...

Share This Page