Push back

A

{AGUT2} {H}-IWIK

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 said:
::push_back(int)' in function main()"

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<facetInfo> mySurface;
while(!inf.getline(buffer, 128, ' ').eof())
{
if (buffer == ncheck)
{
normFlag=1;
compFlag=1;
vertNum=1;
if (facetNum !=0)
{
mySurface.push_back(facetNum);
}
...... etc
}
}

Alex
 
?

=?iso-8859-1?Q?Juli=E1n?= Albo

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

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

Regards.
 
K

Kevin Goodsell

{AGUT2} {H}-IWIK said:
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:




Am I missing something?

TIA

#include <stdlib>
#include <math>

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.
#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?

The 'using namespace std' covers the previous using lines. It's
generally better not to bring in the entire namespace, though.
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

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.
int main()
{
char fileName[255];

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

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

ifstream inf(fileName.c_str());

You also need to check that it opened successfully.
cout << fileName;
char buffer[128];

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'.)
char * ehWhy;
int vertNum=1;
int facetNum=0;
OK...

int normFlag=0;
int vertFlag=0;
int compFlag=0;
double holder;
string ncheck = "normal";
string vcheck = "vertex";

It kind of looks like you want these to be constants. If so, declare
them const.
// 10234 facets
vector<facetInfo> mySurface;
OK...

while(!inf.getline(buffer, 128, ' ').eof())

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::getline. It reads into a string
instead of a char array, and automatically resizes the string:

while (getline(inf, buffer, ' '))
{
if (buffer == ncheck)
{
normFlag=1;
compFlag=1;
vertNum=1;
if (facetNum !=0)
{
mySurface.push_back(facetNum);

Not OK. facetNum is an int. mySurface contains facetInfos, not ints.
}
...... etc
}
}

Alex

-Kevin
 
A

{AGUT2} {H}-IWIK

#include said:
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.

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

Thanks,

Alex.
 
K

Kevin Goodsell

{AGUT2} {H}-IWIK said:
I understand that .h headers stopped being used with the ratified C++ -

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> &
I take it that the cmath and cstdlib are the new templates(headers??)
that replace them?

They are headers, not templates.

-Kevin
 
C

Chris Dams

Hello,

{AGUT2} {H}-IWIK said:
#include <stdlib>
#include <math>

This should be cstdlib and cmath instead.
#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?

That's 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<facetInfo> mySurface;
while(!inf.getline(buffer, 128, ' ').eof())
{
if (buffer == ncheck)
{
normFlag=1;
compFlag=1;
vertNum=1;
if (facetNum !=0)
{
mySurface.push_back(facetNum);

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.
}
...... etc
}
}

Have a nice day,
Chris Dams
 
S

Stephen Howe

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

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
 

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,774
Messages
2,569,599
Members
45,163
Latest member
Sasha15427
Top