Ask Your Question
-1

How to push_back to a vector

asked 2013-10-21 03:18:02 -0500

dogucan159 gravatar image

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?

edit retag flag offensive close merge delete

Comments

1

-1: "It is not working" is not a helpful error description.

SR gravatar imageSR ( 2013-10-21 07:41:29 -0500 )edit

2 answers

Sort by ยป oldest newest most voted
4

answered 2013-10-21 05:26:51 -0500

Guanta gravatar image
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
edit flag offensive delete link more

Comments

I have tried your recommend again and again but problem is go on.

dogucan159 gravatar imagedogucan159 ( 2013-10-21 06:17:25 -0500 )edit
1

which error message do you get?

Guanta gravatar imageGuanta ( 2013-10-22 02:15:52 -0500 )edit

_CrtIsValidHeapPointer(pUsrData) expression in error message

dogucan159 gravatar imagedogucan159 ( 2013-10-22 06:23:13 -0500 )edit
1

not very informative - please compile in debug mode and use a debugger (e.g. gdb) to find the line of code which fails

Guanta gravatar imageGuanta ( 2013-10-22 06:45:29 -0500 )edit

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; } //...

dogucan159 gravatar imagedogucan159 ( 2013-10-22 06:57:14 -0500 )edit
1

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.

Guanta gravatar imageGuanta ( 2013-10-22 08:37:50 -0500 )edit
dogucan159 gravatar imagedogucan159 ( 2013-10-22 08:41:15 -0500 )edit

http://pastebin.com/3H9Hb19F This is also .cpp file of .h file

dogucan159 gravatar imagedogucan159 ( 2013-10-22 08:42:48 -0500 )edit
1

answered 2013-10-21 18:21:02 -0500

stereomatching gravatar image

updated 2013-10-21 22:15:22 -0500

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++

edit flag offensive delete link more
Login/Signup to Answer

Question Tools

Stats

Asked: 2013-10-21 03:18:02 -0500

Seen: 3,782 times

Last updated: Oct 21 '13