I have many nodes, done data is stored in a struct like this:
Each node instance is stored in a vector like this:Code:struct BriteNodeInfo { int nodeId; double xCoordinate; double yCoordinate; int inDegree; int outDegree; int asId; std::string type; };
Problem: How do I wrire a function that write in a .txt file my node data like this:Code:typedef std::vector<BriteNodeInfo> BriteNodeInfoList; BriteNodeInfoList m_briteNodeInfoList;
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"; }




Reply With Quote
