How to push_back to a vector
This is my vector.
vector (Vec4i) lines; I have tried this but It is not working.
lines.push_back((0,0,10,10));
How can i do this job correctly?
std::vector<cv::Vec4i> lines // I guess this is what you have
lines.push_back(cv::Vec4i(0,0,10,10)); // in this way you can add another Vec4i to your lines-vector
I have tried your recommend again and again but problem is go on.
_CrtIsValidHeapPointer(pUsrData) expression in error message
if(xaxis!=(it2)[0]) { line(skeleton,Point((it2)[0],yaxis),Point(xaxis,yaxis),color); writeToFile((it2)[0],yaxis,xaxis,yaxis,i); lines.push_back(Vec4i((it2)[0],yaxis,xaxis,yaxis)); // LINE OF CODE WHICH FAILS ++i; } //...
Please show some more lines (maybe the complete function) and use sth like http://pastebin.com - this comment function is very bad to read code.
http://pastebin.com/3H9Hb19F This is also .cpp file of .h file
In c++11, we have a better api--emplace_back
std::vector<cv::Vec4i> lines;
lines.emplace_back(0, 0, 10, 10);
clang++ and g++ already support emplace_back(remember to add the flag c++11 or c++0x) I don't know about the situation of visual c++
Remember to include your header file and make sure you link to the correct library
#include<vector>
#include <opencv2/core/core.hpp>
int main()
{
std::vector<cv::Vec4i> lines;
lines.emplace_back(0, 0, 10, 10);
}
if your compiler don't support emplace_back yet use push_back suggested by Guanta
Besides, please take a look at c++ primer 5 edition(ch1~ch16) This could help you write robust, efficient and elegant codes by c++
Asked: 2013-10-21 03:18:02 -0600
Seen: 4,894 times
Last updated: Oct 21 '13
-1: "It is not working" is not a helpful error description.