Thread: Writing variables in a vector

  1. #1
    Registered User
    Join Date
    May 2005
    Location
    Toronto, Canada
    Posts
    257

    Writing variables in a vector

    Hey,

    I have a vector of structs, and I want to write one variable at one point in the code and the other variable and a different one. Here's the struct:
    Code:
    struct structLink
    {
    	CString EDFParam;
    	int Index;
    	CString BParam;
    };
    and I want to write the BParams in one loop and then the coresponding paramName in a different one.
    I'm teying to use something like this:
    Code:
    vars.vectParmSelected[pos].EDFParam = FAD.vectDL[i].Param;
    			pos++;
    and then the same methood to write to the BParam. The above line is the first time the vector is used.
    How would it be possible to do this?
    Everything is relative...

  2. #2
    Registered User
    Join Date
    Oct 2001
    Posts
    2,934
    I may misunderstand your question, but I'll give it a try. If the indexes match up, you can use push_back() in the first loop, then the for-loop index to access each vector element (like the code you posted) in the second loop.
    Code:
    //First loop
    structLink temp;
    .
    .
    temp.EDFParam = FAD.vectDL[i].Param;
    vars.vectParmSelected.push_back(temp);
    Otherwise you may need to create a temporary vector of CString for one of the two variables, then add it to the other vector later.

  3. #3
    Registered User
    Join Date
    May 2005
    Location
    Toronto, Canada
    Posts
    257
    Yep, that's what I ended up doing. I used push_back to initiate the vector and then I used the indecies to change the one CSting entries.

    Thanks.
    Everything is relative...

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Vectors
    By naseerhaider in forum C++ Programming
    Replies: 11
    Last Post: 05-09-2008, 08:21 AM
  2. vector of arrays of pointers to structures
    By Marksman in forum C++ Programming
    Replies: 13
    Last Post: 02-01-2008, 04:44 AM
  3. Replies: 3
    Last Post: 11-28-2006, 03:44 PM
  4. my vector class..easy dynamic arrays
    By nextus in forum C++ Programming
    Replies: 5
    Last Post: 02-03-2003, 10:14 AM
  5. Operators for 3D Vector Mathematics
    By Anarchist in forum C++ Programming
    Replies: 10
    Last Post: 01-31-2003, 07:33 PM