Push back

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • {AGUT2} {H}-IWIK

    Push back

    Hi!

    I'm implementing a new method of data input for my program using the
    push_back(int) function.

    When I compile my code (Borland free compiler), I get:

    "Could not find a match for 'vector<facetin fo, allocator<facet info>[color=blue]
    >::push_back(in t)' in function main()"[/color]

    Am I missing something?

    TIA

    #include <stdlib>
    #include <math>
    #include <iostream>
    #include <iomanip>
    #include <fstream>
    #include <vector>
    #include <string>
    #include <algorithm>

    using std::cout;
    using std::cin;
    using std::ifstream;
    using std::string;
    using namespace std; //I don't need the previous lines, right?

    struct facetInfo {
    double v1x;
    double v1y;
    double v1z;
    double v2x;
    double v2y;
    double v2z;
    double v3x;
    double v3y;
    double v3z;
    double nox;
    double noy;
    double noz;
    }; // Semicolon necessary


    int main()
    {
    char fileName[255];
    cout << "Enter the name of the input *.STL file (including extension): ";
    cin >> fileName;
    ifstream inf(fileName);
    cout << fileName;
    char buffer[128];
    char * ehWhy;
    int vertNum=1;
    int facetNum=0;
    int normFlag=0;
    int vertFlag=0;
    int compFlag=0;
    double holder;
    string ncheck = "normal";
    string vcheck = "vertex";

    // 10234 facets
    vector<facetInf o> mySurface;
    while(!inf.getl ine(buffer, 128, ' ').eof())
    {
    if (buffer == ncheck)
    {
    normFlag=1;
    compFlag=1;
    vertNum=1;
    if (facetNum !=0)
    {
    mySurface.push_ back(facetNum);
    }
    ...... etc
    }
    }

    Alex

    --
    Reply to:alex an.ti livingstone sp@am btinternet.com cutting the usual...
  • Julián Albo

    #2
    Re: Push back

    {AGUT2} {H}-IWIK escribió:
    [color=blue]
    > I'm implementing a new method of data input for my program using the
    > push_back(int) function.[/color]

    A vector of facetInfo does not have a push_back(int) function, it has a
    push_back(facet Info).

    Regards.

    Comment

    • Kevin Goodsell

      #3
      Re: Push back

      {AGUT2} {H}-IWIK wrote:
      [color=blue]
      > Hi!
      >
      > I'm implementing a new method of data input for my program using the
      > push_back(int) function.
      >
      > When I compile my code (Borland free compiler), I get:
      >
      > "Could not find a match for 'vector<facetin fo, allocator<facet info>
      >[color=green]
      >> ::push_back(int )' in function main()"[/color]
      >
      >
      > Am I missing something?
      >
      > TIA
      >
      > #include <stdlib>
      > #include <math>[/color]

      The previous 2 headers don't exist in C++. You need to add either a 'c'
      on the front or a '.h' on the back of each.
      [color=blue]
      > #include <iostream>
      > #include <iomanip>
      > #include <fstream>
      > #include <vector>
      > #include <string>
      > #include <algorithm>
      >
      > using std::cout;
      > using std::cin;
      > using std::ifstream;
      > using std::string;
      > using namespace std; //I don't need the previous lines, right?[/color]

      The 'using namespace std' covers the previous using lines. It's
      generally better not to bring in the entire namespace, though.
      [color=blue]
      >
      > struct facetInfo {
      > double v1x;
      > double v1y;
      > double v1z;
      > double v2x;
      > double v2y;
      > double v2z;
      > double v3x;
      > double v3y;
      > double v3z;
      > double nox;
      > double noy;
      > double noz;
      > }; // Semicolon necessary[/color]

      Looks like you could break that up a little more... if you had a Point
      class or something like that:

      struct facetInfo {
      Point v1;
      Point v2;
      Point v3;
      Point no;
      };

      Or

      Strict facetInfo {
      Point v[3];
      Point no;
      };

      Could make it much simpler to deal with.
      [color=blue]
      >
      >
      > int main()
      > {
      > char fileName[255];[/color]

      You #included <string>. Why not use it? This is an ideal place.

      string fileName;
      [color=blue]
      > cout << "Enter the name of the input *.STL file (including
      > extension): ";
      > cin >> fileName;
      > ifstream inf(fileName);[/color]

      ifstream inf(fileName.c_ str());

      You also need to check that it opened successfully.
      [color=blue]
      > cout << fileName;
      > char buffer[128];[/color]

      string buffer;

      Or

      vector<char> buffer;

      Or

      vector<char> buffer(128);

      might be better, depending on how you intend to use it.

      (In fact, scanning ahead it looks like you should definitely use 'string
      buffer'.)
      [color=blue]
      > char * ehWhy;
      > int vertNum=1;
      > int facetNum=0;[/color]

      OK...
      [color=blue]
      > int normFlag=0;
      > int vertFlag=0;
      > int compFlag=0;
      > double holder;
      > string ncheck = "normal";
      > string vcheck = "vertex";[/color]

      It kind of looks like you want these to be constants. If so, declare
      them const.
      [color=blue]
      >
      > // 10234 facets
      > vector<facetInf o> mySurface;[/color]

      OK...
      [color=blue]
      > while(!inf.getl ine(buffer, 128, ' ').eof())[/color]

      A few problems here. One, don't test for eof. There are other ways file
      input can fail - you should check for general failure. Two, use
      std::getline instead of std::istream::g etline. It reads into a string
      instead of a char array, and automatically resizes the string:

      while (getline(inf, buffer, ' '))
      [color=blue]
      > {
      > if (buffer == ncheck)
      > {
      > normFlag=1;
      > compFlag=1;
      > vertNum=1;
      > if (facetNum !=0)
      > {
      > mySurface.push_ back(facetNum);[/color]

      Not OK. facetNum is an int. mySurface contains facetInfos, not ints.
      [color=blue]
      > }
      > ...... etc
      > }
      > }
      >
      > Alex
      >[/color]

      -Kevin
      --
      My email address is valid, but changes periodically.
      To contact me please use the address from a recent posting.

      Comment

      • {AGUT2} {H}-IWIK

        #4
        Re: Push back

        > A vector of facetInfo does not have a push_back(int) function, it has a[color=blue]
        > push_back(facet Info).[/color]

        Thank you _so_ much!

        Alex

        --
        Reply to:alex an.ti livingstone sp@am btinternet.com cutting the usual...
        If you fancy a chat, #agut on quakenet :)

        Comment

        • {AGUT2} {H}-IWIK

          #5
          Re: Push back

          >> #include <stdlib>[color=blue][color=green]
          >> #include <math>[/color]
          >
          > The previous 2 headers don't exist in C++. You need to add either a 'c'
          > on the front or a '.h' on the back of each.[/color]

          I understand that .h headers stopped being used with the ratified C++ - I
          take it that the cmath and cstdlib are the new templates(heade rs??) that
          replace them?

          Thanks,

          Alex.

          --
          Reply to:alex an.ti livingstone sp@am btinternet.com cutting the usual...

          Comment

          • Kevin Goodsell

            #6
            Re: Push back

            {AGUT2} {H}-IWIK wrote:
            [color=blue][color=green][color=darkred]
            >>> #include <stdlib>
            >>> #include <math>[/color]
            >>
            >>
            >> The previous 2 headers don't exist in C++. You need to add either a
            >> 'c' on the front or a '.h' on the back of each.[/color]
            >
            >
            > I understand that .h headers stopped being used with the ratified C++ -[/color]

            Not quite. There are still 18 headers taken from C that end in '.h'
            (including <math.h> and <stdlib.h>), but they are deprecated in favor of
            version that drop the '.h' and add a 'c' to the front (e.g., <cmath> &
            <cstdlib>.
            [color=blue]
            > I take it that the cmath and cstdlib are the new templates(heade rs??)
            > that replace them?[/color]

            They are headers, not templates.

            -Kevin
            --
            My email address is valid, but changes periodically.
            To contact me please use the address from a recent posting.

            Comment

            • Chris Dams

              #7
              Re: Push back

              Hello,

              {AGUT2} {H}-IWIK <alexan.tilivin gstonesp@ambtin ternet.com> wrote in message news:<oprvar7ax pp508op@mercury .nildram.net>.. .
              [color=blue]
              > #include <stdlib>
              > #include <math>[/color]

              This should be cstdlib and cmath instead.
              [color=blue]
              > #include <iostream>
              > #include <iomanip>
              > #include <fstream>
              > #include <vector>
              > #include <string>
              > #include <algorithm>
              >
              > using std::cout;
              > using std::cin;
              > using std::ifstream;
              > using std::string;
              > using namespace std; //I don't need the previous lines, right?[/color]

              That's right.
              [color=blue]
              > struct facetInfo {
              > double v1x;
              > double v1y;
              > double v1z;
              > double v2x;
              > double v2y;
              > double v2z;
              > double v3x;
              > double v3y;
              > double v3z;
              > double nox;
              > double noy;
              > double noz;
              > }; // Semicolon necessary
              >
              >
              > int main()
              > {
              > char fileName[255];
              > cout << "Enter the name of the input *.STL file (including extension): ";
              > cin >> fileName;
              > ifstream inf(fileName);
              > cout << fileName;
              > char buffer[128];
              > char * ehWhy;
              > int vertNum=1;
              > int facetNum=0;
              > int normFlag=0;
              > int vertFlag=0;
              > int compFlag=0;
              > double holder;
              > string ncheck = "normal";
              > string vcheck = "vertex";
              >
              > // 10234 facets
              > vector<facetInf o> mySurface;
              > while(!inf.getl ine(buffer, 128, ' ').eof())
              > {
              > if (buffer == ncheck)
              > {
              > normFlag=1;
              > compFlag=1;
              > vertNum=1;
              > if (facetNum !=0)
              > {
              > mySurface.push_ back(facetNum);[/color]

              Not possible. You declared mySurface to be a vector consisting of
              facetInfo, so push_back should receive an instance of this class. You
              are giving it an int here.
              [color=blue]
              > }
              > ...... etc
              > }
              > }[/color]

              Have a nice day,
              Chris Dams

              Comment

              • Stephen Howe

                #8
                Re: Push back

                > I understand that .h headers stopped being used with the ratified C++ - I[color=blue]
                > take it that the cmath and cstdlib are the new templates(heade rs??) that
                > replace them?[/color]

                They are the new headers.
                One thing

                cmath and cstdlib are such that you will need using clauses unlike math.h
                and stdlib.h

                Stephen Howe


                Comment

                Working...