I have a list of Point objects in C++11 and I want to combine each point's string value into a longer string. I have a method to get the point as a string in a certain format, but I can't figure out how to call that method while iterating through the list.
This is my code:
list<Point> points;
string results = "";
for (int i = 0; i < num_points; i++) {
Point ptemp = Point(random01(), random01());
points.push_back(ptemp);
results += ptemp.getStr();
}
string log_output = "";
string sep = ",";
list<Point>::iterator iter;
for (iter = points.begin(); iter != points.end(); ++iter) {
// get the first three points in the log.txt format
log_output += *iter.getRawStr(",") + " , ";
}
I'm getting this error:
error: ‘std::__cxx11::list<Point>::iterator’ {aka ‘struct std::_List_iterator<Point>’} has no member named ‘getRawStr’
177 | log_output += *iter.getRawStr(",") + " , ";
I've tried taking away the asterisk, using to_string() instead, and reformatting the loop to use an increasing integer i with the iterator methods called separately inside the loop, but it still doesn't work. I've also tried researching it, but I've only seen cout << *iter, not how to specifically call methods from the iterator. What should I do?
.operator has higher precedence than*. You need(*iter).getRawStr()oriter->getRawStr()