2-D vectors..string2int

From: Rich (dodd004_at_csusm.edu)
Date: 07/31/04


Date: 31 Jul 2004 09:57:30 -0700

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;



Relevant Pages

  • Re: Instrumentation + BCEL | ASM
    ... final String owner, ... Strangely enough, with this method added, I can only transform methods with exactly one argument of type String). ... But I don't seem to know how to get hold of method signature, so there can be problems if consecutive threads call timed methods with the same name, but different signatures. ... private void genStartCode() { ...
    (comp.lang.java.programmer)
  • Yet another way to use Java
    ... * @param mainClass e.g. FontShower, ... StompProject (String mainClass, ... * does this project have a jar ... void mkDescBtm() ...
    (comp.lang.java.programmer)
  • Re: Creating multiple instances of objects
    ... > Can you post the server maincode, your IDL, and the full stack ... // Naming Service specification. ... typedef string tTbls; ... void SetCurrentTableraises; ...
    (comp.object.corba)
  • Re: Command Parser
    ... shortcut to writing the full declaration of 'void function1(Connection ch, ... UserList users, string ARGS)'. ... Then you can instantiate the class with the invariant arguments passed to the constructor or otherwise initialized as part of the instantiation, and then just pass the non-invariant data (the command argument) to each method when it's called. ...
    (microsoft.public.dotnet.languages.csharp)
  • Re: UDP broadcasting problem
    ... private void Client_OnConnect(string msg) ... get {return mygroupPort;} ...
    (microsoft.public.dotnet.languages.csharp)