Writing variables in a vector

This is a discussion on Writing variables in a vector within the C++ Programming forums, part of the General Programming Boards category; Hey, I have a vector of structs, and I want to write one variable at one point in the code ...

  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, 03:44 AM
  3. Replies: 3
    Last Post: 11-28-2006, 02:44 PM
  4. my vector class..easy dynamic arrays
    By nextus in forum C++ Programming
    Replies: 5
    Last Post: 02-03-2003, 09:14 AM
  5. Operators for 3D Vector Mathematics
    By Anarchist in forum C++ Programming
    Replies: 10
    Last Post: 01-31-2003, 06:33 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21