Hi

I need to write data which I have successfully read in from a text file, to a new file. The original text file contains data for many objects. The read in data is stored using stl vectors in 3 nested objects: Structure, Polygon and Point i.e. a Structure contains >=2 Polygons which in turn comprises >=3 Points. Attached are the .h and .cpp files since they are quite large (planROI.cpp in particular).

Everything was going swimmingly (printing read in values to screen with std::cout) until I tried to write the data out to file.

There are no compilation errors, but when I execute the program the vectors go out of range giving the following error message:

terminate called after throwing an instance of 'std::out_of_range'
what(): vector::_M_range_check


Found 1 PTV(s)
PTV0: "PTV"
Opened file : /home/mark/PTV0.txt


Inspecting the files you will see that I have also tried overloading the ostream << operator for the objects. This did not help.

I know this is a rather vague description of my problem, but I am a bit of a loss to explain this at the moment. I suspect the problem lies with the use of the constructors and member functions to populate the stl vectors that the Structure and Polygon objects contain.

Thanks in anticipation


Mark

Recommended Answers

All 3 Replies

Hello Mark

I have seen your code, and there is small error

file planROI.cpp, line 231

for (int curPoint;curPoint!=this->polygons.at(curPoly).polygonPoints.size();curPoint++)

variable curPoint is not initialized!

'std::out_of_range' means you are accessing an element of the vector that does not exist.

Here is my suggestion. If the input is working properly, then hardcode some values for the input. Then post the shortest compilable code that demonstrates the problem (hopefully < 20 lines). This makes it very easy for us to see what is going on (without having to download 5 files and look through a bunch of code that likely doesn't have anything to do with the problem).

David

Hello Mark

I have seen your code, and there is small error

file planROI.cpp, line 231

for (int curPoint;curPoint!=this->polygons.at(curPoly).polygonPoints.size();curPoint++)

variable curPoint is not initialized!

Many thanks Alex!! The same error crept in at line 252 too!

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.