The problem is pretty basic.
(I am puzzled why the search didn't find anything)
I have a rectangular "picture" that stores it's pixel color line
after line in a std::vector
I want to copy a rectangular region out of that picture.
How would I elegantly code this in c++?
My first try:
template <class T> std::vector<T> copyRectFr...
Hi,
Before asking you my question directly, I'm going to describe the nature of my prolem.
I'm coding a 2D simulation using C++/OpenGL with the GLFW library. And I need to manage a lot of threads properly. In GLFW we have to call the function:
thread = glfwCreateThread(ThreadFunc, NULL); (the first parameter is the function that'll exec...
I want to be able to initialize a vector of a size 'SIZE' before main. Normally I would do
static vector<int> myVector(4,100);
int main() {
// Here I have a vector of size 4 with all the entries equal to 100
}
But the problem is that I would like to initialize the first item of the vector to be of a certain value, and the othe...
Hello,
I'm trying to build a simple OCR program as a project for an image processing class. So far I've been able to "read" an image containing just ones and zeros
I differentiate between ones and zeros by first identifying edge contours, then counting the number of contours per character, such that 1=one contour, 0=two contours.
...
In my Java project, I have a vector of various types of Traders. These different types of traders are subclasses of the Trader class. Right now, I have a method that takes a Trader as an argument and stores it 50 or so times in the vector. I am having problems because storing the same object 50 times is just storing 50 references of the ...
How can I fill up two vectors and combine them with eachother (either index or an object type in class). I guess if I use index to combine them, then the sorting can be handeld with Collections.sort otherwise I have to create a comparator.
On plus we have to code down to the 1.4 convention. No generics pls...
To make your imagination e...
I use vectors, lists, strings and wstrings obsessively in my code. Are there any catch 22s involved that should make me more interested in using arrays from time to time, chars and wchars instead?
Basically, if working in an environment which supports the standard template library is there any case using the primitive types is actually ...
I'm using C++ and it's STL.
I have a large (100MB+) text file. This file just has a lot of "words" (strings separated by whitespace) like:
sdfi sidf ifids sidf assd fdfd fdfd ddd ddd
I need to put each of these "words" in a vector:
vector<string> allWordsInFile;
So for each word that I read from the file, i do:
allWordsInFile.pu...
Just wondering, because of a problem I am running into, is it possible to create a vector of pointers? And if so, how? Specifically concerning using iterators and .begin() with it, ie: How would I turn this vector into a vector of pointers:
class c
{
void virtual func();
};
class sc:public c
{
void func(){cout<<"using func...
What exactly is an "assert", or more specifically, how do I get rid of an error. When I create a vector of pointers to a class with data member int x, and then do this:
for(I=antiviral_data.begin();I<antiviral_data.end();I++)
{
if((*I)->x>maxx)
{
antiviral_data.erase(I);
}
}
And run the program, I get no errors until...
Hai C++
How to create a 2D vector where in like 2D array
a[0][1]=98;
a[0][2]=95;
a[0][3]=99;
a[0][4]=910;
a[1][0]=98;
a[1][1]=989;
a[1][2]=981;
a[1][3]=987;
how do the same in vector?
Thank you in advance.
...
i am trying to create a mock shopping cart for a uni project. im using two java classes Item and shoppingCart, shopping cart uses a vector to store Items and then writes them to a file. i am trying to use the classes on a jsp page but when i try to write to the file i get an java.io.WriteAbortedException: writing aborted; java.io.NotSeri...
I would like to take advantage of all the goodness of the newer Vector class for FP10, but it seems it is marked as final.
I am doing some intensive mathematical processing in Actionscript, and repeatedly process arrays of Numbers. I have previously been using my own subclass of Array(I call it NumericArray), with added functions such a...
I'd like to reorder the items in a vector, using another vector to specify the order:
char A[] = { 'a', 'b', 'c' };
size_t ORDER[] = { 1, 0, 2 };
vector<char> vA(A, A + sizeof(A) / sizeof(*A));
vector<size_t> vOrder(ORDER, ORDER + sizeof(ORDER) / sizeof(*ORDER));
reorder_naive(vA, vOrder);
// A is now { 'b', 'a', 'c' }
The fo...
Hi
I am doing my assignment in Network architecture 1, where I have to implement a distance vector routing at each node.
At each node, I have a thread which listens for incoming DatagramPackets containing routing information from neighboring nodes only on a specific port. When a datagram arrives, the thread processes that datagram, an...
Is there any way to build paths in Cairo by combining two paths together through Boolean operations such as Union, Difference, and Intersection? I'm working on a vector graphics application that uses Cairo to do its rendering and would like to give my users the ability to combine paths together in this manner, but I can't find a way to d...
My question is simple: are std::vector elements guaranteed to be contiguous? In order word, can I use the pointer to the first element of a std::vector as a C-array?
If my memory serves me well, the C++ standard did not make such guarantee. However, the std::vector requirements were such that it was virtually impossible to meet them i...
I have a class (foo) that contains a vector.
If i try iterating over the elements in the vector like so:
for(vector<random>::iterator it = foo.getVector().begin();
it != foo.getVector().end(); ++it) {
cout << (*it) << endl;
}
The first element is always corrupted and returns garbage data.
However, if do something like:
...
How come that random deletion from a std::vector is faster than a std::list? What I'm doing to speed it up is swapping the random element with the last and then deleting the last.
I would have thought that the list would be faster since random deletion is what it was built for.
for(int i = 500; i < 600; i++){
swap(vector1[i], vector...
I created a program, and it uses the vector.h #include, and iterators, etc... But when I run the program, under certain circumstances (I'm still trying to figure out what those would be) I get an assertion error refering me to line 98 of vector.h. I went to line 98 of vector.h and got this:
#if _HAS_ITERATOR_DEBUGGING
if (this->_...