Hi everyone, i have some issues with the vector class, actually i want to sort my vector or just find something within. I'm tryin to use <algorithm>, made for using list and vector, but it doesn't work very well.... i have many errors while compilating...
Here is the source code :
(struct centre with three integers, x y and mountain)
{
std::vector<cen tre> vec;
vec.reserve(500 );
vec.at(1).x = w;
vec.at(1).y = u;
vec.at(1).mount ain = z;
}
and then i use the method sort(vec.begin( ), vec.end()); i'd like to sort my vector by mountain....
could you help me please ?? thanks
Mickael.
1 1559 horace1 1,510
Recognized Expert Top Contributor
have a look at this simple example ov sorting avector -
int idata[]={1,5,7,4,9,78,45,23,56,-2,-8,56};
-
vector<int> v;
-
for (int i=0;i<sizeof(idata)/sizeof(int); i++) v.push_back(idata[i]);
-
for(int i=0;i<v.size();i++) cout << v[i] << " ";
-
cout << endl;
-
sort(v.begin(), v.end());
-
for(int i=0;i<v.size();i++) cout << v[i] << " ";
-
it pushes the int data onto the vector then sorts it
Sign in to post your reply or Sign up for a free account.
Similar topics |
by: Alan Benn |
last post by:
(VC6) When I use the STL <vector> template as follows:
#include <vector>
....
vector<CString> m_nameList; // Names of the chips
I get these compiler warnings :
C:\Program Files\Microsoft Visual Studio\VC98\INCLUDE\xmemory(39) : warning
C4100: '_P' : unreferenced formal parameter
|
by: sw |
last post by:
Hi,
Is it possible to insert a class <vec> which has a vector<double>
member, into the vector<vec> veclist for e.g?
I've been getting compilation errors when trying to insert using the
vector method push_back() ->
c:\program files\microsoft visual studio\vc98\include\xutility(39) :
error C2679: binary '=' : no operator defined which...
|
by: uotani.arisa |
last post by:
Hi,
Can someone tell me how to declare a pointer to a vector of pointers?
I'm just not sure how to do this...
I've tried essentially the following:
vector<string *> * v;
....
|
by: aaragon |
last post by:
I am trying to create a vector of type T and everything goes fine until
I try to iterate over it. For some reason, the compiler gives me an
error when I declare
std::vector<T>::iterator iter;
Any ideas why is tihs happening? The code is as follows:
template <class T>
struct StdVectorStorage
{
std::vector<T>* _storage;
|
by: toton |
last post by:
Hi,
I want to have a vector like class with some additional functionality
(cosmetic one). So can I inherit a vector class to add the addition
function like,
CorresVector : public vector<Corres>{
public:
void addCorres(Corres& c); //it do little more than push_back
function.
}
| |
by: mast2as |
last post by:
Hi everyone
I am working on some code that uses colors. Until recently this code
used colors represented a tree floats (RGB format) but recently changed
so colors are now defined as spectrum. The size of the vector went from
3 (RGB) to 151 (400 nm to 700 with a sample every 2nm). The variables
are using a simple Vector class defined as...
|
by: krunalbauskar |
last post by:
Hi,
Explicit instantiation of STL vector demands explicit instantiation of
all the templates it using internally.
For example -
<snippet>
#include <iostream>
#include <vector>
|
by: Jia |
last post by:
Hi all,
I have a class foo which has a static vector of pointers of type base
class, and a static function to set this vector.
#include <iostream>
#include <vector>
using namespace std;
class super{
protected:
|
by: helge |
last post by:
What is the best way to implement a vector in space R3, i.e a vector
holding three floats, supporting arithmetic operations, dot and cross
product etc in c++? is there a standard library class for this?
|
by: Ramon F Herrera |
last post by:
Newbie alert: I come from C programming, so I still have that frame of
mind, but I am trying to "Think in C++". In C this problem would be
solved using unions.
Hello:
Please consider the snippet below. I have some objects which are
derived (subclassed?, subtyped?) from simpler ones, in increasing
size. There is a linear hierarchy. I need...
|
by: marktang |
last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main...
| |
by: Hystou |
last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it.
First, let's disable language...
|
by: tracyyun |
last post by:
Dear forum friends,
With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the...
|
by: agi2029 |
last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then...
|
by: isladogs |
last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM).
In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules.
He will explain when you may want to use classes...
|
by: conductexam |
last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one.
At the time of converting from word file to html my equations which are in the word document file was convert...
|
by: adsilva |
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
| |
by: 6302768590 |
last post by:
Hai team
i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
|
by: muto222 |
last post by:
How can i add a mobile payment intergratation into php mysql website.
| |