Need help with my conversion utility...

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Martin Jørgensen

    #1

    Need help with my conversion utility...

    Hi,

    I've had a introductory C++ course in the spring and haven't programmed in
    C++ for a couple of months now (but I have been programmed in C since
    january). So I decided to do my conversion utility in C++, before I forget
    everything. But it doesn't compile:



    ------------
    cat export_tex.C
    #include <iostream>
    #include <fstream>
    #include <string>

    using namespace std;


    /*************** *************** *************** ****
    * *
    * This program takes data from some .vtk *
    * input-files and exports them to .tex-format *
    * *
    *************** *************** *************** ****/


    int main()
    {
    /* will contain LaTeX preamble etc */
    string LaTeX_header = "test, bla.bla... \n\begin{docume nt}\n";
    string LaTeX_tail = "\end{document\ n}";

    string current_data_ty pe;
    char* valid_data_type s[3] = {"Temperatur e", "Rho*cp", "Cell_energ y"};
    string read_line;

    unsigned int filenumber; /* current data file number */
    unsigned int number_of_lines ; /* tells how many data lines follows */



    /*************** *************** *************** ***************
    * conversion loop - continue as long as data-files exists *
    *************** *************** *************** ***************/

    for(unsigned int i=0; i<999; i++)
    {

    ifstream infile("file", i, ".vtk"); /* file[filenumber].vtk */
    if( infile )
    {
    infile >read_line;

    /* ??? if read_line == one of the "valid_data_typ es" ...
    then begin conversion... Else: read a new line */
    /* valid lines beginn with:
    "SCALARS" + spc + |current_data_t ype| + spc */


    /* test: cout read_line; */

    /* tex_file[filenumber].tex */
    ofstream outfile("tex_fi le", i, ".tex");


    /*************** *************** ****
    * do the actual conversion here *
    *************** *************** ****/

    outfile << LaTeX_header;

    /*
    for(unsigned int linenumber=1; linenumber<numb er_of_lines;
    linenumber++)
    {
    infile >something;
    outfile << converted_somet hing;
    }
    */

    outfile << LaTeX_tail;

    }

    if( ! infile ) /* can't open file? Then finish */
    break;
    }


    cout << filenumber+1 << " number of .tex files written" << endl << endl;

    return 0;
    }


    ------------

    As you see it's probably very much C-style and not very good C++-style, as I
    did my bachelor project in C (and this conversion utility is a continuation
    of my bs.c project).

    First step: How can I make this compile? Suggestions are most welcome...


    I get a lot of strange things when I try to compile... Such as:

    /usr/include/c++/4.1.0/i586-suse-linux/bits/c++config.h:43: error: expected
    constructor, destructor, or type conversion before ‘namespace’
    /usr/include/c++/4.1.0/i586-suse-linux/bits/c++config.h:47: error:
    ‘__gnu_debug_ def’ is not a namespace-name
    /usr/include/c++/4.1.0/i586-suse-linux/bits/c++config.h:47: error: expected
    namespace-name before ‘;’ token
    ...... etc. etc...


    Best regards
    Martin Jørgensen

    --
    ---------------------------------------------------------------------------
    Home of Martin Jørgensen - http://www.martinjoergensen.dk

  • Moonlit

    #2
    Re: Need help with my conversion utility...

    Hi,

    Well this seems to come from the compiler itself, this means there is
    something wrong with it. Just a wild guess; you might try to include the
    '#include' s in a different order. If that doesn't work install another
    version of g++.


    Regards, Ron AF Greve



    "Martin Jørgensen" <hotmail_spam@h otmail.comwrote in message
    news:4530148b$0 $822$edfadb0f@d read12.news.tel e.dk...
    Hi,
    >
    I've had a introductory C++ course in the spring and haven't programmed in
    C++ for a couple of months now (but I have been programmed in C since
    january). So I decided to do my conversion utility in C++, before I forget
    everything. But it doesn't compile:
    >
    >
    >
    ------------
    >cat export_tex.C
    >
    #include <iostream>
    #include <fstream>
    #include <string>
    >
    using namespace std;
    >
    >
    /*************** *************** *************** ****
    * *
    * This program takes data from some .vtk *
    * input-files and exports them to .tex-format *
    * *
    *************** *************** *************** ****/
    >
    >
    int main()
    {
    /* will contain LaTeX preamble etc */
    string LaTeX_header = "test, bla.bla... \n\begin{docume nt}\n";
    string LaTeX_tail = "\end{document\ n}";
    >
    string current_data_ty pe;
    char* valid_data_type s[3] = {"Temperatur e", "Rho*cp", "Cell_energ y"};
    string read_line;
    >
    unsigned int filenumber; /* current data file number */
    unsigned int number_of_lines ; /* tells how many data lines follows */
    >
    >
    >
    /*************** *************** *************** ***************
    * conversion loop - continue as long as data-files exists *
    *************** *************** *************** ***************/
    >
    for(unsigned int i=0; i<999; i++)
    {
    >
    ifstream infile("file", i, ".vtk"); /* file[filenumber].vtk */
    if( infile )
    {
    infile >read_line;
    >
    /* ??? if read_line == one of the "valid_data_typ es" ...
    then begin conversion... Else: read a new line */
    /* valid lines beginn with:
    "SCALARS" + spc + |current_data_t ype| + spc */
    >
    >
    /* test: cout read_line; */
    >
    /* tex_file[filenumber].tex */
    ofstream outfile("tex_fi le", i, ".tex");
    >
    >
    /*************** *************** ****
    * do the actual conversion here *
    *************** *************** ****/
    >
    outfile << LaTeX_header;
    >
    /*
    for(unsigned int linenumber=1; linenumber<numb er_of_lines;
    linenumber++)
    {
    infile >something;
    outfile << converted_somet hing;
    }
    */
    >
    outfile << LaTeX_tail;
    >
    }
    >
    if( ! infile ) /* can't open file? Then finish */
    break;
    }
    >
    >
    cout << filenumber+1 << " number of .tex files written" << endl << endl;
    >
    return 0;
    }
    >
    >
    ------------
    >
    As you see it's probably very much C-style and not very good C++-style, as
    I
    did my bachelor project in C (and this conversion utility is a
    continuation
    of my bs.c project).
    >
    First step: How can I make this compile? Suggestions are most welcome...
    >
    >
    I get a lot of strange things when I try to compile... Such as:
    >
    /usr/include/c++/4.1.0/i586-suse-linux/bits/c++config.h:43: error:
    expected
    constructor, destructor, or type conversion before 'namespace'
    /usr/include/c++/4.1.0/i586-suse-linux/bits/c++config.h:47: error:
    '__gnu_debug_de f' is not a namespace-name
    /usr/include/c++/4.1.0/i586-suse-linux/bits/c++config.h:47: error:
    expected
    namespace-name before ';' token
    ..... etc. etc...
    >
    >
    Best regards
    Martin Jørgensen
    >
    --
    ---------------------------------------------------------------------------
    Home of Martin Jørgensen - http://www.martinjoergensen.dk
    >

    Comment

    • Moonlit

      #3
      Re: Need help with my conversion utility...



      Hi,

      Wait a minute, your file ends with .cc or not? Make sure you compile it with
      g++ and not gcc.


      Regards, Ron AF Greve



      "Moonlit" <news moonlit xs4all nlwrote in message
      news:45301cce$0 $4528$e4fe514c@ news.xs4all.nl. ..
      Hi,
      >
      Well this seems to come from the compiler itself, this means there is
      something wrong with it. Just a wild guess; you might try to include the
      '#include' s in a different order. If that doesn't work install another
      version of g++.
      >
      >
      Regards, Ron AF Greve
      >

      >
      "Martin Jørgensen" <hotmail_spam@h otmail.comwrote in message
      news:4530148b$0 $822$edfadb0f@d read12.news.tel e.dk...
      >Hi,
      >>
      >I've had a introductory C++ course in the spring and haven't programmed
      >in
      >C++ for a couple of months now (but I have been programmed in C since
      >january). So I decided to do my conversion utility in C++, before I
      >forget
      >everything. But it doesn't compile:
      >>
      >>
      >>
      >------------
      >>cat export_tex.C
      >>
      >#include <iostream>
      >#include <fstream>
      >#include <string>
      >>
      >using namespace std;
      >>
      >>
      >/*************** *************** *************** ****
      >* *
      >* This program takes data from some .vtk *
      >* input-files and exports them to .tex-format *
      >* *
      >************** *************** *************** *****/
      >>
      >>
      >int main()
      >{
      > /* will contain LaTeX preamble etc */
      > string LaTeX_header = "test, bla.bla... \n\begin{docume nt}\n";
      > string LaTeX_tail = "\end{document\ n}";
      >>
      > string current_data_ty pe;
      > char* valid_data_type s[3] = {"Temperatur e", "Rho*cp", "Cell_energ y"};
      > string read_line;
      >>
      > unsigned int filenumber; /* current data file number */
      > unsigned int number_of_lines ; /* tells how many data lines follows */
      >>
      >>
      >>
      > /*************** *************** *************** ***************
      > * conversion loop - continue as long as data-files exists *
      > *************** *************** *************** ***************/
      >>
      > for(unsigned int i=0; i<999; i++)
      > {
      >>
      > ifstream infile("file", i, ".vtk"); /* file[filenumber].vtk */
      > if( infile )
      > {
      > infile >read_line;
      >>
      > /* ??? if read_line == one of the "valid_data_typ es" ...
      > then begin conversion... Else: read a new line */
      > /* valid lines beginn with:
      > "SCALARS" + spc + |current_data_t ype| + spc */
      >>
      >>
      > /* test: cout read_line; */
      >>
      > /* tex_file[filenumber].tex */
      > ofstream outfile("tex_fi le", i, ".tex");
      >>
      >>
      > /*************** *************** ****
      > * do the actual conversion here *
      > *************** *************** ****/
      >>
      > outfile << LaTeX_header;
      >>
      > /*
      > for(unsigned int linenumber=1; linenumber<numb er_of_lines;
      >linenumber++ )
      > {
      > infile >something;
      > outfile << converted_somet hing;
      > }
      > */
      >>
      > outfile << LaTeX_tail;
      >>
      > }
      >>
      > if( ! infile ) /* can't open file? Then finish */
      > break;
      > }
      >>
      >>
      > cout << filenumber+1 << " number of .tex files written" << endl << endl;
      >>
      > return 0;
      >}
      >>
      >>
      >------------
      >>
      >As you see it's probably very much C-style and not very good C++-style,
      >as I
      >did my bachelor project in C (and this conversion utility is a
      >continuation
      >of my bs.c project).
      >>
      >First step: How can I make this compile? Suggestions are most welcome...
      >>
      >>
      >I get a lot of strange things when I try to compile... Such as:
      >>
      >/usr/include/c++/4.1.0/i586-suse-linux/bits/c++config.h:43: error:
      >expected
      >constructor, destructor, or type conversion before 'namespace'
      >/usr/include/c++/4.1.0/i586-suse-linux/bits/c++config.h:47: error:
      >'__gnu_debug_d ef' is not a namespace-name
      >/usr/include/c++/4.1.0/i586-suse-linux/bits/c++config.h:47: error:
      >expected
      >namespace-name before ';' token
      >..... etc. etc...
      >>
      >>
      >Best regards
      >Martin Jørgensen
      >>
      >--
      >---------------------------------------------------------------------------
      >Home of Martin Jørgensen - http://www.martinjoergensen.dk
      >>
      >
      >

      Comment

      • Michael

        #4
        Re: Need help with my conversion utility...

        cat export_tex.C
        ....
        First step: How can I make this compile? Suggestions are most welcome...
        It's complaining about the word "using," which is C++ specific.

        My guess - change the filename to .CC or .cc or .cpp or something like
        that. At least a couple of compilers I've used have a heuristic that
        checks filename and compiles in C mode or C++ mode depending. And be
        sure you're using the C++ version of the compiler (g++ instead of gcc).

        I tried compiling in VS, and it complains, but not about that.

        Michael

        Comment

        • Thomas Tutone

          #5
          Re: Need help with my conversion utility...


          Martin Jørgensen wrote:
          Hi,
          >
          I've had a introductory C++ course in the spring and haven't programmed in
          C++ for a couple of months now (but I have been programmed in C since
          january). So I decided to do my conversion utility in C++, before I forget
          everything. But it doesn't compile:
          >
          >
          >
          ------------
          cat export_tex.C
          >
          #include <iostream>
          #include <fstream>
          #include <string>
          >
          using namespace std;
          >
          >
          /*************** *************** *************** ****
          * *
          * This program takes data from some .vtk *
          * input-files and exports them to .tex-format *
          * *
          *************** *************** *************** ****/
          >
          >
          int main()
          {
          /* will contain LaTeX preamble etc */
          string LaTeX_header = "test, bla.bla... \n\begin{docume nt}\n";
          string LaTeX_tail = "\end{document\ n}";
          Keep in mind that C++ uses "\" as an escape character, so the above
          line probably doesn't do what you expect.

          string current_data_ty pe;
          char* valid_data_type s[3] = {"Temperatur e", "Rho*cp", "Cell_energ y"};
          string read_line;
          >
          unsigned int filenumber; /* current data file number */
          unsigned int number_of_lines ; /* tells how many data lines follows */
          >
          >
          >
          /*************** *************** *************** ***************
          * conversion loop - continue as long as data-files exists *
          *************** *************** *************** ***************/
          >
          for(unsigned int i=0; i<999; i++)
          {
          >
          ifstream infile("file", i, ".vtk"); /* file[filenumber].vtk */
          The above line does not use a valid constructor for ifstream.
          ifstream's constructor is declared as follows:

          explicit basic_ifstream( const char *filename, ios_base::openm ode mode =
          ios_base::in);

          In other words, your three argument constructor isn't valid, AFAIK.

          if( infile )
          {
          infile >read_line;
          >
          /* ??? if read_line == one of the "valid_data_typ es" ...
          then begin conversion... Else: read a new line */
          /* valid lines beginn with:
          "SCALARS" + spc + |current_data_t ype| + spc */
          >
          >
          /* test: cout read_line; */
          >
          /* tex_file[filenumber].tex */
          ofstream outfile("tex_fi le", i, ".tex");
          >
          >
          /*************** *************** ****
          * do the actual conversion here *
          *************** *************** ****/
          >
          outfile << LaTeX_header;
          >
          /*
          for(unsigned int linenumber=1; linenumber<numb er_of_lines;
          You never initialized number_of_lines .

          That's a start, anyway.

          Best regards,

          Tom

          Comment

          • Phlip

            #6
            Re: Need help with my conversion utility...

            Martin Jørgensen wrote:
            >cat export_tex.C
            Is this C or C++? Sometimes compilers trigger on the filename suffix, so see
            if that fixes it.

            (However, your compiler's forum is the best place for subsequent questions
            on how to drive it...)
            I get a lot of strange things when I try to compile... Such as:
            >
            /usr/include/c++/4.1.0/i586-suse-linux/bits/c++config.h:43: error:
            expected
            constructor, destructor, or type conversion before 'namespace'
            A 'config.h' is often the very first header file of any translation unit,
            because (again, off-topically) many compilers rely on install scripts that
            build config.h with their platform-specific details.

            However, your compiler can't understand its first C++ line. Maybe the
            compiler is in C mode, and then maybe the error message incorrectly
            specifies C things.

            Alternately, maybe your compiler is old and doesn't understand namespaces,
            which are new. Try these:

            $ which c++

            That might show a path with a version other than 4.1

            $ ls -l `which c++`

            That might show a link to path with a version other than 4.1

            $ c++ -v

            And that might show version info other than 4.1.

            And, naturally, you might be calling some wrapper other than c++, such as
            g++. Check your makefile.

            --
            Phlip
            http://www.greencheese.us/ZeekLand <-- NOT a blog!!!


            Comment

            • Martin Jørgensen

              #7
              Re: Need help with my conversion utility...

              Thomas Tutone wrote:

              -snip-
              > /* will contain LaTeX preamble etc */
              > string LaTeX_header = "test, bla.bla... \n\begin{docume nt}\n";
              > string LaTeX_tail = "\end{document\ n}";
              >
              Keep in mind that C++ uses "\" as an escape character, so the above
              line probably doesn't do what you expect.
              Thanks. I think \\ must be the correct thing then.

              -snip-
              > for(unsigned int i=0; i<999; i++)
              > {
              >>
              > ifstream infile("file", i, ".vtk"); /* file[filenumber].vtk */
              >
              The above line does not use a valid constructor for ifstream.
              ifstream's constructor is declared as follows:
              >
              explicit basic_ifstream( const char *filename, ios_base::openm ode mode =
              ios_base::in);
              >
              In other words, your three argument constructor isn't valid, AFAIK.
              Damn... I wanted the loop to process these file names:

              file000.vtk
              file001.vtk
              file002.vtk
              file003.vtk
              .....
              .....

              So that explains the "file" + the counter in the loop, "i", + extension. How
              to do this, then? And my original suggestion also didn't take into account
              that the numbers should always take up 3 characters. Here's my
              C-implementation (this is how I make the output filenames in C):


              --- for-loop --
              if(*filecounter >999)
              {
              printf("Error! Too many results have been written.\n\n");
              quit_program(__ FILE__, __LINE__);
              }

              sprintf(fname, "file_%03d.vtk" , *file_counter);
              ---


              How to this in C++? - In an "elegant" way, ofcourse...
              > if( infile )
              > {
              > infile >read_line;
              Here I want to read a line... Not sure I did it correctly...
              > /* ??? if read_line == one of the "valid_data_typ es" ...
              > then begin conversion... Else: read a new line */
              I must compare the beginning of each line with the word "SCALARS". Once I
              find that word in the beginning of a line, I must see if it's one of the 3
              char *valid_data_typ es[3].

              -snip-
              > /*
              > for(unsigned int linenumber=1; linenumber<numb er_of_lines;
              >
              You never initialized number_of_lines .
              >
              That's a start, anyway.
              You're right, thanks... The number of lines is something I'll have to
              extract from inside the data-file and I haven't exactly figured out how to
              do that yet...


              I can now compile my program. I had a stupid "x" in the top of the file and
              after I removed the ifstream infile("file", i, ".vtk") line (and also for
              the ofstream) I got something usable:

              Complete program follows:
              ------------------------
              cat output_to_latex .cpp
              #include <iostream>
              #include <fstream>
              #include <string>

              using namespace std;


              /*************** *************** *************** ****
              * *
              * This program takes data from some .vtk *
              * input-files and exports them to .tex-format *
              * *
              *************** *************** *************** ****/


              int main()
              {
              /* will contain LaTeX preamble etc */
              string LaTeX_header = "test, bla.bla... \n\\begin{docum ent}\n";
              string LaTeX_tail = "\\end{document }\n";

              string current_data_ty pe;
              char* valid_data_type s[3] = {"Temperatur e", "Rho*cp", "Cell_energ y"};
              string read_line;

              unsigned int filenumber; /* current data file number */
              unsigned int number_of_lines ; /* tells how many data lines follows */



              /*************** *************** *************** ***************
              * conversion loop - continue as long as data-files exists *
              *************** *************** *************** ***************/

              for(unsigned int i=0; i<999; i++)
              {

              ifstream infile("file000 .vtk");
              // ifstream infile("file", i, ".vtk"); /* file[filenumber].vtk */

              if( infile )
              {
              infile >read_line;

              /* ??? if read_line == one of the "valid_data_typ es" ...
              then begin conversion... Else: read a new line */
              /* valid lines beginn with:
              "SCALARS" + spc + |current_data_t ype| + spc */


              /* test: cout read_line; */
              ofstream outfile("tex_fi le000.tex");
              /* should be tex_file[filenumber].tex, something like:
              ofstream outfile("tex_fi le", i, ".tex"); */


              /*************** *************** ****
              * do the actual conversion here *
              *************** *************** ****/

              outfile << LaTeX_header;

              /*
              for(unsigned int linenumber=1; linenumber<numb er_of_lines;
              linenumber++)
              {
              infile >something;
              outfile << converted_somet hing;
              }
              */

              outfile << LaTeX_tail;

              }

              if( ! infile ) /* can't open file? Then finish */
              break;
              }


              cout << filenumber+1 << " number of .tex files written" << endl << endl;

              return 0;
              }

              ------------------------

              Suggestions are welcome... I probably should make a file-class and then have
              a smaller main-function with a loop that just increments the file-counter
              and calls some function in that class... or something...

              I still have a few problems to solve...


              Best regards
              Martin Jørgensen

              --
              ---------------------------------------------------------------------------
              Home of Martin Jørgensen - http://www.martinjoergensen.dk

              Comment

              • Martin Jørgensen

                #8
                Re: Need help with my conversion utility...

                Phlip wrote:
                Martin Jørgensen wrote:
                >
                >>cat export_tex.C
                >
                Is this C or C++? Sometimes compilers trigger on the filename suffix, so
                see if that fixes it.
                I've read that .c is C and .C is C++ on unix... And it didn't make any
                difference to use .cpp, but now I use .cpp even though it isn't necessary.



                Best regards
                Martin Jørgensen

                --
                ---------------------------------------------------------------------------
                Home of Martin Jørgensen - http://www.martinjoergensen.dk

                Comment

                • BobR

                  #9
                  Re: Need help with my conversion utility...


                  Michael wrote in message
                  <1160781410.471 748.64260@k70g2 000cwa.googlegr oups.com>...
                  >
                  cat export_tex.C
                  >...
                  >
                  >First step: How can I make this compile? Suggestions are most welcome...
                  >
                  >It's complaining about the word "using," which is C++ specific.
                  >
                  >My guess - change the filename to .CC or .cc or .cpp or something like
                  >that. At least a couple of compilers I've used have a heuristic that
                  >checks filename and compiles in C mode or C++ mode depending. And be
                  >sure you're using the C++ version of the compiler (g++ instead of gcc).
                  [ GCC Docs ]
                  For any given input file, the file name suffix determines what kind of
                  compilation is done:

                  file.c
                  C source code which must be preprocessed.
                  [ use gcc ]

                  file.cc
                  file.cp
                  file.cxx
                  file.cpp
                  file.c++
                  file.C
                  C++ source code which must be preprocessed. Note that in .cxx, the last
                  two
                  letters must both be literally x. Likewise, .C refers to a literal
                  capital C.
                  [ use g++ ]

                  --
                  Bob R
                  POVrookie


                  Comment

                  • BobR

                    #10
                    Re: Need help with my conversion utility...


                    Martin Jørgensen wrote in message
                    <45302fc7$0$895 $edfadb0f@dread 12.news.tele.dk >...
                    Thomas Tutone wrote:

                    -snip-
                    >
                    >Keep in mind that C++ uses "\" as an escape character, so the above
                    >line probably doesn't do what you expect.
                    >Thanks. I think \\ must be the correct thing then.
                    Yup!

                    -snip-
                    >> for(unsigned int i=0; i<999; i++){
                    >> ifstream infile("file", i, ".vtk"); /* file[filenumber].vtk */
                    >>
                    >The above line does not use a valid constructor for ifstream.
                    >In other words, your three argument constructor isn't valid, AFAIK.
                    >Damn... I wanted the loop to process these file names:
                    >file000.vtk
                    >file001.vtk
                    >file002.vtk
                    >file003.vtk
                    >....
                    /* "
                    So that explains the "file" + the counter in the loop, "i", + extension. How
                    to do this, then?
                    And my original suggestion also didn't take into account
                    that the numbers should always take up 3 characters. Here's my
                    C-implementation (this is how I make the output filenames in C):

                    How to this in C++? - In an "elegant" way, ofcourse...
                    " */

                    One way is to use 'stringstream' (header <sstream>), then put it in a
                    std::string.

                    #include <string>
                    #include <sstream // for std::ostringstr eam
                    #include <iomanip // for std::setfill(), std::setw()

                    int fnumb(5); // you will use the 'int' in your for loop.
                    std::ostringstr eam Oss;
                    Oss << "file" <<std::setfil l( '0' )<<std::setw( 3 )<< fnumb << ".vtk";
                    std::string Filename;
                    Filename = Oss.str();
                    // or just: std::string Filename( Oss.str() );

                    std::cout<<" Filename ="<<Filename<<s td::endl;
                    // --- output ---
                    // Filename =file005.vtk

                    ifstream infile( Filename.c_str( ) ); /* file[filenumber].vtk */

                    >> if( infile ){
                    >> infile >read_line;
                    >Here I want to read a line... Not sure I did it correctly...
                    std::string read_line;

                    std::getline( infile, read_line );
                    >> /* ??? if read_line == one of the "valid_data_typ es" ...
                    >> then begin conversion... Else: read a new line */
                    >I must compare the beginning of each line with the word "SCALARS". Once I
                    >find that word in the beginning of a line, I must see if it's one of the 3
                    >char *valid_data_typ es[3].
                    std::string FindThis( "SCALARS" );
                    if( read_line.find( FindThis ) != std::string::np os ){
                    /* "SCALARS" is in read_line */
                    std::string FindThis1( valid_data_type s[0] ); // may need 'adjusting'
                    (*)
                    if( read_line.find( FindThis1 ) != std::string::np os ){
                    /* valid_data_type s[0] is in read_line */
                    }
                    }



                    Read-up on std::string and std::streams, then you'll have much power at your
                    command! <G>

                    Hope that helps. This ain't homework is it?
                    --
                    Bob R
                    POVrookie


                    Comment

                    • Martin Jørgensen

                      #11
                      Re: Need help with my conversion utility...

                      BobR wrote:

                      -snip-
                      Read-up on std::string and std::streams, then you'll have much power at
                      your command! <G>
                      >
                      Hope that helps. This ain't homework is it?
                      Nope. No teacher gives me any homework that extends my bs.c. project because
                      I'm not a software/electrical engineer or something like that. I'm a
                      mechanical engineer (studying to get my masters degree) so the only thing
                      the teachers want is Matlab programming. This is just so I don't forget all
                      I learned about c++.

                      I took your suggestions and implemented some of it and rewrote everything...
                      It's much more C++'ish, but I can't compile it...

                      Just copy/paste, compile and tell me your suggestions.


                      ----- unfinished code begins ----
                      #include <iostream>
                      #include <fstream>
                      #include <string>
                      #include <sstream/* for std::ostringstr eam */
                      #include <iomanip/* for std::setfill(), std::setw() */
                      #include <vector>
                      #include <ctype.h/* for isspace */

                      using namespace std;


                      std::string trim( std::string const& s )
                      {
                      // Create string from first non-whitespace to last non-whitespace

                      return std::string ( std::find_if( s.begin(), s.end(), std::not
                      (std::ptr_fun(& isspace) ) ),
                      std::find_if( s.rbegin(), s.rend(), std::not
                      (std::ptr_fun(& isspace) ) ).base() );

                      }

                      /*************** *************** *************** ********/

                      void convert_data(un signed int linenumber,
                      const string &cur_ifilena me, const string &cur_ofilena me)
                      {

                      string LaTeX_header = "test, bla.bla... \n\\begin{docum ent}\n";
                      string LaTeX_tail = "\\end{document }\n";

                      /*************** *************** *****
                      * do the actual conversion here *
                      *************** *************** *****/

                      // ofstream outfile( cur_ofilename:: c_str() ); <<<< WRONG???

                      // outfile << LaTeX_header;
                      /*
                      for(unsigned int linenumber=1; linenumber<numb er_of_lines; linenumber++)
                      {
                      infile >something;
                      outfile << converted_somet hing;
                      }
                      */
                      // outfile << LaTeX_tail;
                      }

                      /*************** *************** *************** ********/

                      void set_file_names( unsigned int filenumber, string &cur_ifilena me,
                      string &cur_ofilena me)
                      {

                      /*************** **********
                      * Creating file names *
                      *************** **********/

                      ostringstream filename_genera ted;

                      filename_genera ted << "file" << setfill('0') <<
                      setw(3) << filenumber << ".vtk";
                      cur_ifilename = filename_genera ted.str();
                      filename_genera ted << "tex_file" << setfill('0') <<
                      setw(3) << filenumber << ".tex";

                      /* WRONG!!! = file000.vtktex_ file000.tex ??? */
                      cur_ofilename = filename_genera ted.str();

                      cout << "Input filename = " << cur_ifilename << endl;
                      cout << "Output filename = " << cur_ofilename << endl;
                      }

                      /*************** *************** *************** ********/

                      int main()
                      {
                      string current_data_ty pe;
                      vector<stringpo ssible_data_typ es;
                      int data_type;
                      string read_line;

                      unsigned int filenumber; /* current data file number */
                      unsigned int linenumber; /* current line */
                      unsigned int number_of_lines ; /* how many data lines follows */

                      string cur_ifilename; /* input */
                      string cur_ofilename; /* output */



                      /*************** *************** *************** **********
                      * scan the first input file for possible data types *
                      *************** *************** *************** **********/

                      set_file_names( 0, cur_ifilename, cur_ofilename);

                      ifstream infile( cur_ifilename.c _str() );
                      while( infile )
                      {
                      getline( infile, read_line);

                      if( read_line.find( "SCALARS") != string::npos )
                      {
                      /* "SCALARS" was found in read_line */
                      cout << read_line << endl;

                      /* "SCALARS" + spc + |current_data_t ype| + spc */
                      current_data_ty pe = trim( read_line );
                      cout << current_data_ty pe << endl;
                      possible_data_t ypes.push_back( current_data_ty pe);
                      }
                      }


                      /*************** *************** ***************
                      * ask which data type should be converted *
                      *************** *************** **************/
                      data_type = 0;
                      for( vector<string:: const_iterator it = possible_data_t ypes.begin();
                      it != possible_data_t ypes.end(); ++it)
                      {
                      cout << data_type << ": " << possible_data_t ypes(*it) << endl;
                      }
                      cout << endl << "Which datatype (number) should be converted ? ";
                      cin >data_type;

                      current_data_ty pe = possible_data_t ypes[data_type];



                      /*************** *************** *
                      * convert data in all files *
                      *************** *************** */

                      for(unsigned int filenumber=0; filenumber<999; filenumber++)
                      {

                      set_file_names( filenumber, cur_ifilename, cur_ofilename);

                      linenumber = 0;
                      ifstream infile( cur_ifilename.c _str() );

                      while( infile )
                      {

                      linenumber++; /* counter for debugging */
                      getline( infile, read_line);

                      if( read_line.find( "SCALARS") != string::npos )
                      {
                      /* "SCALARS" was found in read_line */
                      cout << read_line << endl; /* debug */

                      /* if( read_line contains "current_data_t ype" - convert)
                      /* "SCALARS" + spc + |current_data_t ype| + spc */

                      convert_data( linenumber, cur_ifilename, cur_ofilename);

                      cout << "Program not finished. Come back later" << endl;
                      return 1;
                      }


                      cout << "Program not finished. Come back later" << endl;
                      return 1;
                      }
                      }


                      cout << filenumber+1 << " number of .tex files written" << endl << endl;
                      return 0;
                      }

                      ----- unfinished code ends ----


                      Best regards
                      Martin Jørgensen

                      --
                      ---------------------------------------------------------------------------
                      Home of Martin Jørgensen - http://www.martinjoergensen.dk

                      Comment

                      • BobR

                        #12
                        Re: Need help with my conversion utility...


                        Martin Jørgensen wrote in message
                        <4530c88d$0$837 $edfadb0f@dread 12.news.tele.dk >...
                        BobR wrote:

                        -snip-
                        >This ain't homework is it?
                        >Nope.
                        Good. We don't like to do the homework for someone, but rather, guide a
                        student.
                        I like to play with code, so I usually leave the homework to the guys higher
                        on the ladder than me. <G>

                        >I took your suggestions and implemented some of it and rewrote everything...
                        >It's much more C++'ish, but I can't compile it...

                        >Just copy/paste, compile and tell me your suggestions.
                        I'll check out your code in a little bit. I just wanted to mention the below:
                        >----- unfinished code begins ----
                        // #include <ctype.h/* for isspace */
                        // For C++ you want to use:
                        #include <cctype/* for isspace */

                        This will put all those things in 'ctype' in the 'std::' namespace. You won't
                        have to change any of your code because you are using 'using namespace std;'.
                        (otherwise you would use 'std::isspace() '.)


                        /*************** *************** *************** ********/
                        >void convert_data(un signed int linenumber,
                        const string &cur_ifilena me, const string &cur_ofilename) {
                        // ofstream outfile( cur_ofilename:: c_str() ); <<<< WRONG???

                        ofstream outfile( cur_ofilename.c _str() ); // change the qualifier '::' to
                        dot '.'
                        // note: ah, I see you did it correctly below.
                        <snip>



                        /* """ // note: this is my way of 'quoting' since my newsreader doesn't
                        // do it for me (you are posting from a *nix machine?)

                        /*************** *************** *************** ********/
                        void set_file_names( unsigned int filenumber, string &cur_ifilena me,
                        string &cur_ofilename) {
                        /*************** **********
                        * Creating file names *
                        *************** **********/
                        ostringstream filename_genera ted;

                        filename_genera ted << "file" << setfill('0') <<
                        setw(3) << filenumber << ".vtk";
                        cur_ifilename = filename_genera ted.str();
                        filename_genera ted << "tex_file" << setfill('0') <<
                        setw(3) << filenumber << ".tex";
                        /* WRONG!!! = file000.vtktex_ file000.tex ??? */
                        cur_ofilename = filename_genera ted.str();

                        """ */

                        // OK, when you want to 're-use' a stream you need to 'clear' it:

                        ostringstream filename_genera ted;

                        filename_genera ted << "file" << setfill('0') <<
                        setw(3) << filenumber << ".vtk";
                        cur_ifilename = filename_genera ted.str();

                        // -- add this here: --
                        filename_genera ted.str(""); // 'clear' the stream
                        filename_genera ted.clear(); // and 'reset' the stream

                        filename_genera ted << "tex_file" << setfill('0') <<
                        setw(3) << filenumber << ".tex";
                        cur_ofilename = filename_genera ted.str();

                        cout << "Input filename = " << cur_ifilename << endl;
                        cout << "Output filename = " << cur_ofilename << endl;
                        } // set_file_names( unsigned int, string &, string &) end


                        /* """

                        /*************** *************** *************** ********/
                        int main(){
                        string current_data_ty pe;
                        vector<stringpo ssible_data_typ es;
                        int data_type;
                        string read_line;
                        unsigned int filenumber; /* current data file number */
                        unsigned int linenumber; /* current line */
                        unsigned int number_of_lines ; /* how many data lines follows */
                        string cur_ifilename; /* input */
                        string cur_ofilename; /* output */
                        /*************** *************** *************** **********
                        * scan the first input file for possible data types *
                        *************** *************** *************** **********/
                        set_file_names( 0, cur_ifilename, cur_ofilename);
                        ifstream infile( cur_ifilename.c _str() );
                        while( infile ) {
                        getline( infile, read_line);

                        """ */

                        // Try it this way:

                        ifstream infile( cur_ifilename.c _str() );
                        if( not infile ){ /* handle error here */}

                        while( getline( infile, read_line) ) {
                        // ......
                        } // while(getline)


                        That should clear-up a few things. I'll post again after I 'check-out' your
                        code.

                        You may be interested in a little header I've been playing with. It ain't
                        perfect, but, has worked for everything I threw at it.
                        [ assume your file is not super-big (will fit in memory) ]

                        // -------------------------------------------------------
                        // Filer.h
                        // -------------------------------------------------------
                        #ifndef Filer_H
                        #define Filer_H
                        // ----------------------------------------------
                        #include <iostream>
                        #include <ostream // std::endl
                        #include <string>
                        #include <vector>
                        #include <fstream>
                        // --------------------------------------
                        #include <stdexcept>
                        class FilerErr : public std::runtime_er ror { public:
                        FilerErr(const std::string& msg = "") : std::runtime_er ror(msg){}
                        };
                        //use: try{ throw FilerErr(__FILE __": my message");}
                        // --------------------------------------
                        // note: AFAIK vector does not have a virtual destructor, so,
                        // *never* use this class thru a base pointer.

                        class Filer : public std::vector<std ::string{
                        public:
                        // Filer(){}
                        Filer(const char *filename) { Open(filename); }
                        private: // public: if I use Filer() Ctor. Or, 2nd file open
                        void Open(const char *filename) throw(FilerErr) {
                        std::ifstream in(filename);
                        if(!in){ throw FilerErr(__FILE __": Open SonOfABitch! ");}
                        //if(!in)
                        for( std::string line; std::getline(in , line); ){
                        push_back(line) ;
                        }
                        return;
                        } //Open(const char*) throw(MyError)
                        public:
                        void Write(std::ostr eam& out = std::cout) throw(FilerErr) {
                        if(!out){ throw FilerErr(__FILE __": Write SonOfABitch! ");}
                        //if(!in)
                        for(const_itera tor w = begin(); w != end(); ++w)
                        out << *w << std::endl;
                        } //Write(ostream&)
                        }; //class Filer
                        // -------------------------------------------------------
                        #endif //#ifndef Filer_H


                        // --- TestFiler.cpp ---
                        // ----------------------------------------------
                        #include <iostream// just in case<G>
                        #include <fstream>
                        #include <string// just in case<G>
                        #include "Filer.h"

                        int main(){
                        using std::cout; // for NG posting
                        try{
                        cout<<"_____ Filer.h test _____"<<std::en dl;
                        Filer Afile("Filer.h" );
                        // Filer Afile("ErrFiler .h"); // to test exception.
                        Afile.Write( cout );
                        cout<<"\nAfile. size()="<<Afile .size()<<" lines."<<std::e ndl;
                        cout<<"Afile.at (1)="<<Afile.at (1)<<std::endl;

                        std::string FindThis( "// *never* use this class thru a base
                        pointer." );
                        // - the following works, but, needs 'fixing' <G-
                        Filer::iterator FindMain = Afile.begin();
                        for(size_t a(0); a < Afile.size(); ++a){
                        if( Afile.at(a).fin d( FindThis ) != std::string::np os ){
                        FindMain = Afile.begin() + a;
                        }
                        } // for(a)
                        Afile.insert(Fi ndMain, "//__________ inserted line __________");
                        Afile.push_back ("\n//----- This is a copy -----");
                        std::ofstream Ofile("CopyFile r.txt");
                        if( !Ofile){ return EXIT_FAILURE; }
                        Afile.Write( Ofile );
                        cout<<"_____ Filer.h test End _____"<<std::en dl;
                        } // try{}
                        catch(FilerErr &x){
                        cout<<"FilerErr &x.what()="< < x.what() <<std::endl;
                        } // catch(FilerErr& )
                        catch(std::out_ of_range &Oor){
                        cout<<"\ncaught "<<Oor.what()<< std::endl;
                        }
                        catch(...){
                        cout<< "\ncaught something!!" <<std::endl;
                        } //catch(MyError&)
                        return 0;
                        } //main()
                        // -----------------------------------------------------------------END

                        --
                        Bob R
                        POVrookie


                        Comment

                        • Martin Jørgensen

                          #13
                          Re: Need help with my conversion utility...

                          BobR wrote:
                          -snip-
                          >>----- unfinished code begins ----
                          >// #include <ctype.h/* for isspace */
                          >
                          // For C++ you want to use:
                          #include <cctype/* for isspace */
                          Thanks.

                          -snip-
                          // ofstream outfile( cur_ofilename:: c_str() ); <<<< WRONG???
                          >
                          ofstream outfile( cur_ofilename.c _str() ); // change the qualifier '::'
                          to
                          dot '.'
                          // note: ah, I see you did it correctly below.
                          Dough.... Thanks...
                          /* """ // note: this is my way of 'quoting' since my newsreader doesn't
                          // do it for me (you are posting from a *nix machine?)
                          Yes, I try to learn to use emacs and the linux utilities on my suse 10.1
                          laptop machine and sometimes the compiler complains if I use
                          "old-fashioned" // for comments so I manually change all comments to /*
                          */-style...


                          -snip-
                          // OK, when you want to 're-use' a stream you need to 'clear' it:
                          >
                          ostringstream filename_genera ted;
                          >
                          filename_genera ted << "file" << setfill('0') <<
                          setw(3) << filenumber << ".vtk";
                          cur_ifilename = filename_genera ted.str();
                          >
                          // -- add this here: --
                          filename_genera ted.str(""); // 'clear' the stream
                          filename_genera ted.clear(); // and 'reset' the stream
                          Thanks! Very nice... Exactly what I couldn't solve myself...

                          -snip-
                          // Try it this way:
                          >
                          ifstream infile( cur_ifilename.c _str() );
                          if( not infile ){ /* handle error here */}
                          >
                          while( getline( infile, read_line) ) {
                          // ......
                          } // while(getline)
                          >
                          >
                          That should clear-up a few things. I'll post again after I 'check-out'
                          your code.
                          Thanks a lot... That was also a great suggestion as it clears things a bit
                          up...
                          You may be interested in a little header I've been playing with. It ain't
                          perfect, but, has worked for everything I threw at it.
                          [ assume your file is not super-big (will fit in memory) ]
                          -snip-

                          I just quickly tried to compile it and it runs fine... I've always wanted to
                          learn more about this try/catch-thing. So this program is really great for
                          that, I think... See my other reply, which I'll post shortly...

                          Summary: I think I'm almost done with the hardest part, but I only get a
                          single output-file written out............ ... Do you have any idea why?


                          --------- program that's much better than I started out with ------------
                          #include <iostream>
                          #include <fstream>
                          #include <string /* for string manipulations */
                          #include <sstream/* for std::ostringstr eam */
                          #include <iomanip/* for std::setfill(), std::setw() */
                          #include <vector /* sequential container */
                          #include <cctype/* for isspace */


                          using namespace std;


                          /*************** *************** *************** *****
                          * *
                          * This program takes data from some .vtk *
                          * input-files and exports them to .tex-format *
                          * *
                          *************** *************** *************** *****/


                          /*************** *************** *************** ********/

                          std::string trim(std::strin g str)
                          {
                          string::size_ty pe pos = str.find_last_n ot_of(' ');

                          if(pos != string::npos)
                          {
                          str.erase(pos + 1);
                          pos = str.find_first_ not_of(' ');
                          if(pos != string::npos)
                          str.erase(0, pos);
                          }
                          else
                          str.erase(str.b egin(), str.end());

                          return str;
                          }


                          /*************** *************** *************** ********/

                          void convert_data(un signed int linenumber,
                          const string &cur_ifilena me, const string &cur_ofilena me)
                          {

                          string LaTeX_header = "\\begin{docume nt}\n";
                          string LaTeX_tail = "\\end{document }\n";

                          /*************** *************** *****
                          * do the actual conversion here *
                          *************** *************** *****/

                          ofstream outfile( cur_ofilename.c _str() );

                          outfile << LaTeX_header;
                          /*
                          for(unsigned int linenumber=1; linenumber<numb er_of_lines; linenumber++)
                          {
                          infile >something;
                          outfile << converted_somet hing;
                          }
                          */
                          outfile << LaTeX_tail;
                          }

                          /*************** *************** *************** ********/

                          void set_file_names( unsigned int filenumber, string &cur_ifilena me,
                          string &cur_ofilena me)
                          {

                          /*************** **********
                          * Creating file names *
                          *************** **********/

                          ostringstream filename_genera ted;

                          filename_genera ted << "file" << setfill('0') <<
                          setw(3) << filenumber << ".vtk";
                          cur_ifilename = filename_genera ted.str();

                          filename_genera ted.str(""); /* clear stream */
                          filename_genera ted.clear(); /* reset it */

                          filename_genera ted << "tex_file" << setfill('0') <<
                          setw(3) << filenumber << ".tex";

                          cur_ofilename = filename_genera ted.str();
                          }

                          /*************** *************** *************** ********/

                          int main()
                          {
                          string current_data_ty pe;
                          vector<stringpo ssible_data_typ es;
                          int data_type;
                          string read_line;

                          unsigned int filenumber; /* current data file number */
                          unsigned int linenumber; /* current line */
                          unsigned int number_of_lines ; /* how many data lines follows */

                          string cur_ifilename; /* input */
                          string cur_ofilename; /* output */


                          /*************** *************** *************** **********
                          * scan the first input file for possible data types *
                          *************** *************** *************** **********/

                          set_file_names( 0, cur_ifilename, cur_ofilename);

                          ifstream infile( cur_ifilename.c _str() );


                          if( not infile )
                          {
                          cout << "\n\nERROR!\n** ********\nCouln 't open file " << cur_ifilename
                          << endl;
                          return 1;
                          }


                          while( getline( infile, read_line) )
                          {

                          if( read_line.find( "SCALARS") != string::npos )
                          {
                          /* "SCALARS" was found in read_line */

                          /* "SCALARS" + spc + |current_data_t ype| + spc */
                          // remove the word SCALARS from read_line ?!?!
                          current_data_ty pe = trim( read_line );

                          /* I can't figure out how to trim the line correctly */
                          possible_data_t ypes.push_back( current_data_ty pe);
                          }
                          }


                          /*************** *************** ***************
                          * ask which data type should be converted *
                          *************** *************** **************/

                          cout << "************** *************** **************" << endl;
                          data_type = 0;
                          for( vector<string>: :const_iterator it = possible_data_t ypes.begin();
                          it != possible_data_t ypes.end(); ++it)
                          {
                          data_type++;
                          cout << data_type << ": " << *it << endl;
                          }
                          cout << endl << "Which datatype (number) should be converted ? ";
                          cin >data_type;

                          current_data_ty pe = possible_data_t ypes[data_type-1];



                          /*************** *************** *
                          * convert data in all files *
                          *************** *************** */

                          for(filenumber= 0; filenumber<999; filenumber++)
                          {

                          set_file_names( filenumber, cur_ifilename, cur_ofilename);

                          linenumber = 0;
                          ifstream infile( cur_ifilename.c _str() );

                          if( infile )
                          {

                          linenumber++; /* counter for debugging */
                          getline( infile, read_line);

                          if( read_line == current_data_ty pe )
                          {
                          cout << read_line << endl; /* debug */

                          convert_data( linenumber, cur_ifilename, cur_ofilename);
                          }
                          }
                          else
                          break;
                          }


                          cout << endl << filenumber+1 << " number of .tex files written" << endl <<
                          endl;
                          return 0;
                          }

                          -------------------------------------------------------------------------


                          Best regards
                          Martin Jørgensen

                          --
                          ---------------------------------------------------------------------------
                          Home of Martin Jørgensen - http://www.martinjoergensen.dk

                          Comment

                          • Martin Jørgensen

                            #14
                            Re: Need help with my conversion utility...

                            BobR wrote:

                            -snip-
                            // --- TestFiler.cpp ---
                            // ----------------------------------------------
                            #include <iostream// just in case<G>
                            #include <fstream>
                            #include <string// just in case<G>
                            #include "Filer.h"
                            >
                            int main(){
                            using std::cout; // for NG posting
                            try{
                            cout<<"_____ Filer.h test _____"<<std::en dl;
                            Filer Afile("Filer.h" );
                            // Filer Afile("ErrFiler .h"); // to test exception.
                            Afile.Write( cout );
                            cout<<"\nAfile. size()="<<Afile .size()<<" lines."<<std::e ndl;
                            cout<<"Afile.at (1)="<<Afile.at (1)<<std::endl;

                            Okay, so far so good.... But what does the following do?

                            std::string FindThis( "// *never* use this class thru a base
                            pointer." );
                            I can't remember that, although I learned something about that... Do you
                            have a small example of what *not* to do here?
                            // - the following works, but, needs 'fixing' <G-
                            Filer::iterator FindMain = Afile.begin();
                            for(size_t a(0); a < Afile.size(); ++a){
                            if( Afile.at(a).fin d( FindThis ) != std::string::np os ){
                            FindMain = Afile.begin() + a;
                            }
                            } // for(a)
                            Afile.insert(Fi ndMain, "//__________ inserted line __________");
                            Afile.push_back ("\n//----- This is a copy -----");
                            std::ofstream Ofile("CopyFile r.txt");
                            if( !Ofile){ return EXIT_FAILURE; }
                            Afile.Write( Ofile );
                            Hmm... The above code... Perhaps it's a stupid question, but what does it
                            do? The catch-part below, I think is easy to understand...


                            Best regards
                            Martin Jørgensen

                            --
                            ---------------------------------------------------------------------------
                            Home of Martin Jørgensen - http://www.martinjoergensen.dk

                            Comment

                            • BobR

                              #15
                              Re: Need help with my conversion utility...


                              Martin Jørgensen wrote in message
                              <45314a6b$0$904 $edfadb0f@dread 12.news.tele.dk >...
                              BobR wrote:

                              -snip-
                              >// --- TestFiler.cpp ---
                              >// ----------------------------------------------
                              >
                              <snip>
                              >Okay, so far so good.... But what does the following do?
                              > std::string FindThis( "// *never* use this class thru a base
                              >pointer." );
                              It just 'initialises' the string 'FindThis' to the text to search for.

                              std::string FindThis( "Hi." ); // initialization
                              // accomplishes the same thing as:
                              std::string FindThis;
                              FindThis = "Hi."; // assignment

                              >I can't remember that, although I learned something about that... Do you
                              >have a small example of what *not* to do here?
                              For a std::string or my class 'Filer'?
                              For 'Filer', you NEVER want to do this:

                              std::vector<std ::string*MyPoin ter = new Filer("somefile .txt");

                              If 'std::vector' had a virtual destructor, you might get away with it (for
                              simplicity here, just think that an vector::iterato r is a pointer. So, don't
                              do that either.). It can cause a memory leak due to 'slicing' (corrections by
                              experts are welcome.<G>).

                              Filer *MyPointer = new Filer("somefile .txt");
                              ....should/*might* work, but, that's not what I intended. I keep the class
                              simple for simple use.


                              /* """
                              // - the following works, but, needs 'fixing' <G-
                              Filer::iterator FindMain = Afile.begin();
                              for(size_t a(0); a < Afile.size(); ++a){
                              if( Afile.at(a).fin d( FindThis ) != std::string::np os ){
                              FindMain = Afile.begin() + a;
                              }
                              } // for(a)
                              Afile.insert(Fi ndMain, "//__________ inserted line __________");
                              Afile.push_back ("\n//----- This is a copy -----");
                              std::ofstream Ofile("CopyFile r.txt");
                              if( !Ofile){ return EXIT_FAILURE; }
                              Afile.Write( Ofile );
                              """ */
                              >Hmm... The above code... Perhaps it's a stupid question, but what does it
                              >do? The catch-part below, I think is easy to understand...
                              It demonstrates searching through a file ("Filer.h") for a certain text
                              ('FindThis'). Then it 'inserts' a line into the vector (class 'Filer' is
                              derived from a std::vector, so, it acts like a vector.). Then it adds a line
                              "-- This is a copy --" to the end (using 'push_back()').
                              Then it writes the vector out to a file "CopyFiler.txt" . You can open that
                              file in any text editor to verify that the original file and the new file are
                              different.

                              Does that 'splain enough?
                              --
                              Bob R
                              POVrookie


                              Comment

                              Working...