CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 4 of 4

Threaded View

  1. #1
    Join Date
    Oct 2017
    Posts
    1

    Exclamation How to iterate over a vector of many stucts

    I have many nodes, done data is stored in a struct like this:

    Code:
      struct BriteNodeInfo
      {
        int nodeId;
        double xCoordinate;
        double yCoordinate;
        int inDegree;
        int outDegree;
        int asId;
        std::string type;
      };
    Each node instance is stored in a vector like this:

    Code:
      typedef std::vector<BriteNodeInfo> BriteNodeInfoList;
    
      BriteNodeInfoList m_briteNodeInfoList;
    Problem: How do I wrire a function that write in a .txt file my node data like this:

    nodeId0 yCoordinate0 xCoordinate0
    nodeId1 yCoordinate1 xCoordinate1
    nodeId2 yCoordinate2 xCoordinate2
    nodeId3 yCoordinate3 xCoordinate3
    etc...


    I have tried but my iteration syntax is not good enough. Here is my function, please help:

    Code:
    void SaveNodeData (std::string fname)
    {
      ofstream os(fname.c_str(), ios::trunc);
    
      vector<BriteNodeInfo> BriteNodeInfoList;
      BriteNodeInfoList m_briteNodeInfoList;
    
      for (BriteNodeInfoList::Iterator i = m_briteNodeInfoList.Begin(); i != m_briteNodeInfoList.End(); ++i)
        {  
            os << BriteNodeInfo[i].nodeId "\t" << "\t" << BriteNodeInfo[i].yCoordinate << "\t"BriteNodeInfo[i].xCoordinate<< "\n";
        }
    
        os << "\n";
     }
    Last edited by 2kaud; October 27th, 2017 at 01:11 PM. Reason: Added code tags

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured