R
Rich
HI,
I am working on a program which implements the simplex aglorithm. I
have decided to use a vector of vectors to set up my matrix. My
initial thought was to fill the row vector with type string, then
convert all but the operator(<=,>=,=) column to type int. This is
proving a bit harder then I thought. I thought the member function
atoi() did this, but I'm having problems. I'm also having some
problems with this code that I have been working on. I am able to fill
the first row, but that's about it. It seems to skip all but the first
iteration. Do I need to flush the stream buffer? Any tips on the
conversion from string to int(is it possible)? I'm a new user and
appreciate any input at all. Thanks for your time, this has sure taken
up some of mine. I'm compiler on Unix AIX 5.1
class TheMatrix
{
public:
vector <string> P;
vector< vector<string> > M;
~TheMatrix();
void ReadIn();
void AsktoReadIn();
};
// Deconstructor
TheMatrix::~TheMatrix()
{}
void TheMatrix::ReadIn()
{
string eqn;
string temp;
{
cout<<"Enter an equation:\n" << endl;
getline(cin, eqn);
istringstream ins;
ins.str(eqn);
string eqn;
string temp;
{
cout<<"Enter an equation:\n" << endl;
getline(cin, eqn);
istringstream ins;
ins.str(eqn);
//vector <string> X;
while (ins >> temp)
{
P.push_back(temp);
}
M.push_back(P);
}
}
void TheMatrix::AsktoReadIn()
{
char ch;
//ReadIn();
do
{
ReadIn();
cout << "another equation?";
cin >> ch; //seems to be skipping by this???
}while (ch=='y');
for (int i = 0; i < M.size(); i++)
{
for (int j = 0; j < P.size(); j++)
{
cout << P[j] << " ";
}
}
}
int main()
{
TheMatrix A;
A.AsktoReadIn();
return 0;
I am working on a program which implements the simplex aglorithm. I
have decided to use a vector of vectors to set up my matrix. My
initial thought was to fill the row vector with type string, then
convert all but the operator(<=,>=,=) column to type int. This is
proving a bit harder then I thought. I thought the member function
atoi() did this, but I'm having problems. I'm also having some
problems with this code that I have been working on. I am able to fill
the first row, but that's about it. It seems to skip all but the first
iteration. Do I need to flush the stream buffer? Any tips on the
conversion from string to int(is it possible)? I'm a new user and
appreciate any input at all. Thanks for your time, this has sure taken
up some of mine. I'm compiler on Unix AIX 5.1
class TheMatrix
{
public:
vector <string> P;
vector< vector<string> > M;
~TheMatrix();
void ReadIn();
void AsktoReadIn();
};
// Deconstructor
TheMatrix::~TheMatrix()
{}
void TheMatrix::ReadIn()
{
string eqn;
string temp;
{
cout<<"Enter an equation:\n" << endl;
getline(cin, eqn);
istringstream ins;
ins.str(eqn);
string eqn;
string temp;
{
cout<<"Enter an equation:\n" << endl;
getline(cin, eqn);
istringstream ins;
ins.str(eqn);
//vector <string> X;
while (ins >> temp)
{
P.push_back(temp);
}
M.push_back(P);
}
}
void TheMatrix::AsktoReadIn()
{
char ch;
//ReadIn();
do
{
ReadIn();
cout << "another equation?";
cin >> ch; //seems to be skipping by this???
}while (ch=='y');
for (int i = 0; i < M.size(); i++)
{
for (int j = 0; j < P.size(); j++)
{
cout << P[j] << " ";
}
}
}
int main()
{
TheMatrix A;
A.AsktoReadIn();
return 0;