vector

How can I concisely initialize a safe collection in C++?

Possible Duplicate: C++: Easiest way to initialize an STL vector with hardcoded elements I'm learning C++ right now, and I'm looking for a way to quickly and easily initialize a "safe" collection (like a vector) with different values for each element. I'm accustomed to Python's concise list/tuple initializations, and I want to...

What's a good way of *temporarily* sorting a vector?

Hi, I've got a std::vector which I need to sort by selected algorithms for certain operations, but to maintain its original state (e.g. items ordered by when they were entered) the rest of the time. Obviously I can use std::copy to create a temporary vector and sort that, but I'm wondering if there's a better way, possibly by timestamp...

Implementing search engine into website

Hi, I want to develop a website with its own search engine. I would like to use some sort of web framework for all this development, like Django or Rails. The search would be based on vector space model (data is represented as term-by-document matrix). Everything would be running on one server, there would be no extra server for informa...

How can I define a "Do-Nothing" sort?

Hi, I'm working on a system where I need to be able to sort a vector by a given predicate, which my classes shouldn't have control over. Basically, I pass them a derived class and they blindly sort on it. As one of the "delightful quirks", one of the sort patterns is order of entry. Here's what I've got so far. struct Strategy { vi...

c++ insert into vector at known position

I wish to insert into a c++ vector at a known position. I know the c++ library has an insert() function that takes a position and the object to insert but the position type is an iterator. I wish to insert into the vector like I would insert into an array, using a specific index. ...

Cross product of 2 2D vectors

Can anyone provide an example of a function that returns the cross product of TWO 2d vectors? I am trying to implement this algorithm. C code would be great. Thanks. EDIT: found another way todo it that works for 2D and is dead easy. bool tri2d::inTriangle(vec2d pt) { float AB = (pt.y-p1.y)*(p2.x-p1.x) - (pt.x-p1.x)*(p2.y-p1.y);...

index , pointer , iterator , which is better ? when it comes to vectors

hi i'm doing a program that needs high performance of handling vector elements vector<Class_A> object ; 1- which one is fastest to access the elements 2- which is more code simpler and not complex to deal with index ? iterator ? pointer ? ...

allow using vector functions except one ??

i'm lost in this , i have a class that has three vector objects , class A { vector<int> h1; vector<double> h2; vector <int> h3; } i want to have (inherit ) all the vector functions ( push , size etc ) but EXCEPT " erase " function at first i made the objects public but then erase was available , i donno how inheritance...

Is DxScene the "WPF for Delphi"? Anyone used it?

I am playing with DxScene and VxScene: http://www.ksdev.com/dxscene/index.html It looks very nice and powerful: 3d accelerated vector graphics, cross plaform, nice effects, many 2d GUI controls (vector based), good scaling, transparency, rotating (x, y, z), 3d models, etc. Even with many effects, the CPU stays very low (0%)! http://www....

Position of elements in vector

I have several elements in a vector type that are read from cin and then i perfrom some calculations on the vector and it's order of elements gets changed. The problem is that I need to print the positions of the vector elements after the calculations. I don't know how to explain this well that's why i'll give an example: 10 1 100 1000 ...

How do I work with nested vectors in C++?

I'm trying to work with vectors of vectors of ints for a sudoku puzzle solver I'm writing. Question 1: If I'm going to access a my 2d vector by index, do I have to initialize it with the appropriate size first? For example: typedef vector<vector<int> > array2d_t; void readAPuzzle(array2d_t grid) { for(int i = 0; i < 9; i++) ...

Can I do pointer arithmetic on an STL::vector::iterator

This seems to me a simple question but I can't find the answer. Currently I use an iterator to search through a vector and test its elements. I access the elements using std::vector<int>::iterator it; if(*it==0); Can I use the same pointer arithmetic style logic to also test the next element (without altering my iterator)? I first n...

Error in using vector pointer in a function

I have this code, but it won't compile and i can't understand what is wrong - i guess the pointering of the vector is not correct. My idea was to collect some numbers in main() and store them in a vector and array, and then pass the memory address of them to a function, and using a pointers to print the data stored. I came up with this...

Passing command line arguments.

Okay I have updated my code a little, but I am still not exactly sure how to use the vector of command line arguments that I pass. I tried to set it up like the code I have below, but it wont compile. It gives me the error that it cannot find argc and argv: 1>c:\users\chris\documents\visual studio 2008\projects\cplusplustwo\cplusplustwo...

vector assignation on uninitialized memory chunk and similar issues

vector<vector<string> > test for example. g++, you can do test.reserve(10); test[0] = othervector; test[9] = othervector; It doesn't crash. Theory says you shouldn't do it like that because you are assigning a vector to a chunk of memory that believes it is a vector. But it works just like the next one: #include <string> #include <...

No match for call to '(std::pair<unsigned int, unsigned int>) (unsigned int&, unsigned int)'

I don't know what's wrong with the follwing code, it should read numbers and put their value with the position together in a vector of pairs and then sort them and print out the positions. I removed the part with sort - i thought the problem was there, but i received an error on compilation again. #include <iostream> ...

Method for exporting drawn flash/flex UIComponent to vector based print file

Hi, I am creating a flex application where I am using the built in graphics package of flex 3 to draw shapes and things to a UIComponent. I want to be able to export this vector image UIComponent to a vector based file, pdf, eps etc. Are there any tools, libraries, or methods for doing so? I looked at AlivePDF - which works very sl...

Sorting a vector using threads

Hi, Are the vectors defined in the C++ STL re-entrant or thread safe? Can I use two threads and work(in this case sort) on two halfs of a vector without using a mutex? For example: int size = (Data_List.size())/2; Thread A() { ................ // Do we need to lock Data_list with a mutex sort(Data_List.begin(),Data_List.begin()+size...

Storing vector in a struct C++

Why can't I do this: struct sName { vector<int> x; }; It takes only three pointers to store a vector, so I should be able to do this? ...

sizeof() a vector

Hello! I have a vector<set<char> > data structure (transactions database) and I want to know the size of it. When I use sizeof() with each set<char> the size is 24 in spite of the set contains 3, 4 or 5 chars. Later, when I use sizeof() with the vector<set<char> > the size is 12... I suppose this is not the way to know the size of a data...