Inteligent vector

Pages: 12
Hello everyone, I would like to do something with my vectors...I have coded an application to manage something like an store room.

I have boards in stock, I have new ordes, the boards has name and the have as well a date which is composed by day,month and year.

What I want to do is that my program is able to detect with one is the biggest order that I have in my order vector, and It comes out every information about that board, I mean, name, stock, order and date.I guess I'll have to detect which one is the biggest number in the order vector, and after detect on what position it's placed and with that number, It would be easy to have the whole information.

Other thing that I would like to do is, put away the order vector, from biggest to smallest( it I think is so so easy),and according with the new postion of that vector, put away the rest of the vector, to have every information with the same order.

Thank you so much

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
 #include <stdio.h>
#include <iostream>
#include <vector>
#include <string>
using namespace std;

class bench{
	private:
		vector<string> name;
		vector<int>  stock;
		vector<int> order;
		vector<int> day;
		vector<int> month;
		vector<int> year;
		
public:
	
		void CopyName(string boardname);
		void CopyStock(int amountboard);
		void ShowCopyName();
		void ShowCopyStock();
		void ShowNameBoard();
		void ShowBoardStock(int a);
		void CopyDate();
		void CopyOrder();
	};
	
	void bench::CopyOrder(){
		int a;
		cout<< "Insert order:";
		cin>>a;
		order.push_back(a);
	}
	
	void bench::CopyDate(){
		int a = 0,b = 0,c = 0;
		cout << "Insert day:";
		cin>>a;
		day.push_back(a);
		cout << "Insert month:";
		cin>>b;
		month.push_back(b);
		cout<< "Insert year:";
		cin>> c;
		year.push_back(c);
		cin.ignore();
		
	}
	void bench::CopyName(string boardname){
		
			name.push_back(boardname);
	}
	
	void bench::CopyStock(int amountStock){
			
			stock.push_back(amountStock);
	}

	void bench::ShowCopyStock(){
		
		for(vector<string>::iterator it = name.begin();it != name.end();++it){
			cout<<*it;
			cout<<" ";
		}
	}
		void bench::ShowCopyName(){
		
		for(vector<int>::iterator it = stock.begin();it != stock.end();++it){
			cout<<*it;
			cout<<" ";
		}
	}
	
		void bench::ShowBoardStock(int a){
			cout<<"Board name"<< name[a]<< "Board Stock "<< stock[a]<<"Board Order "<< 
			order[a]<<" Board Day"<<day[a]<<"Board Month"<<month[a]<<"Board Year"<<year[a];
			
		}
	
int main(int argc, char **argv)
{
	bench ratula;
	int number = 0;
	string word ("nothing") ;
	string exit ("exit");
	while(word.compare(exit)!=0 ){
	cout<<"Insert  board name:";
	getline (cin,word);
	ratula.CopyName(word);
	cout<<"Insert  board amount:";
	cin>>number;
	ratula.CopyStock (number);
	ratula.CopyDate();
	ratula.CopyOrder();
	cin.ignore();
	}
	int board =0;
	cout<< " what board want to show";
	cin>> board;
	ratula.ShowBoardStock(board);
}
1
2
3
vector<int>::const_iterator it;
it = max_element(order.begin(), order.end());
std::cout<<*it;



this will give you the highest order

std::sort(order.begin(), order.end());

this will sort your vector

Edit : but you have to be careful while sorting as you will lose the postions corresponding to your other elements in your data .
Last edited on
Thank you.

I have sort out the issue og getting the maximun order by this code

1
2
3
4
5
6
7
8
9
10

int bench::ShearchingMaximunOrder(){
			int MaxOrder = 0,PositionMaxOrder = 0;
			for (unsigned int i = 0; i < order.size(); i++)
				if (order[i] > MaxOrder){
				MaxOrder = order[i];
				PositionMaxOrder = i;
				}
			return PositionMaxOrder;
			}


It's giving to me the position of the maximun, and later I can get the whole information of the object.

What I want to do now is sor my order vector, and apply the same sort to the rest vectors, with the goal of have whole vector with the same order.

Thank you!!
Here someone has answered your next question. I hope you would be able to understand it:

http://stackoverflow.com/questions/236172/how-do-i-sort-a-stdvector-by-the-values-of-a-different-stdvector
ok, cool I'll have a look, It seems like is on the right way.

Thanks!!
ASIDE?

Your approach is fine if you want to learn how to handle sets of vectors, but this kind of problem is usually handled using structs or, even better, classes.
http://www.cplusplus.com/doc/tutorial/structures/

Parallel vectors of basic types are generally rather harder to handle than the corresponding single vector of structs!

Similarly, rather than use separate ints for day, month, and year you could use time_t or struct tm
http://www.cplusplus.com/reference/ctime/time_t/
http://www.cplusplus.com/reference/ctime/tm/

Andy
Last edited on
@winsu @andywestken is right , it would be easier for you.
Yes, using structures seems easier, but I cant imagine the way...I guess if I reorder the object that the structur contains using just one variable(the one I want to apply the same order)It'll be ordered how I want.....any suggestion?
You can order a vector in anyway you like by providing the std::sort algorithm with the appropriate compare function or functor object. See the examples here:
http://www.cplusplus.com/reference/algorithm/sort/

And the following example shows how to use use a vector of structs with std::sort in a basic fashion. There are other (cooler?) ways, but as I was not sure how much you know about C++11's new features (e.g. lambda functions, range-based for loops, etc.) I have stuck to a C++03 approach.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
#include <iostream>
#include <iomanip>   // for std::setw, std::left
#include <vector>
#include <string>
#include <algorithm> // for std::sort()
using namespace std;

struct Soldier {
    string name;
    string rank;
    int    serialNumber;
};

void report(const Soldier& s) {
    cout << left
         << setw(10) << s.name << ", "
         << setw(14) << s.rank << ", "
         << setw( 6) << s.serialNumber << "\n";
}

// sort by name predicate (functor)
struct SortByName
{     
    bool operator()(const Soldier& lhs, const Soldier& rhs) {
        return (lhs.name < rhs.name); // dodgy as does not account for case
    }
};

// sort by serial number predicate (function)
bool SortBySerialNumber(const Soldier& lhs, const Soldier& rhs)
{     
    return (lhs.serialNumber < rhs.serialNumber);
}

void PreFillVector(vector<Soldier>& platoon);

int main()
{
    vector<Soldier> platoon;

    // add some soldiers up front as too lazy to type lots!
    PreFillVector(platoon);

    const string exit_cmd = "exit";
    // "exit" is a standard C function, so prefer not to use it
    // as an identifier - http://www.cplusplus.com/reference/cstdlib/exit/

    string name;
    string rank;
    int    serialNumber = 0;

    cout << "Enter soldier details (use \"exit\" for name to finish.)\n";
    cout << "\n";

    while(name != exit_cmd) {
        cout << "Soldier name? ";
        getline(cin, name);
        if(!name.empty() && (name != exit_cmd))
        {
            cout<< "Soldier rank? ";
            cin >> rank;
            cout << "Soldier serial number? ";
            cin >> serialNumber;
            cin.ignore();

            Soldier newRecruit;
            newRecruit.name = name;
            newRecruit.rank = rank;
            newRecruit.serialNumber = serialNumber;
            platoon.push_back(newRecruit);
        }
        cout << "\n";
    }

    cout << "Soldiers (unsorted):\n";
    for(size_t i = 0; platoon.size() > i; ++i) {
        report(platoon[i]);
    }
    cout << "\n";

    // Use 1 based index with user
    while(true)
    {
        int i =0;
        cout << "Which soldier do you want to show (1-" << platoon.size() << ")? ";
        cin >> i;

        if((1 <= i) && (i <= platoon.size()))
        {
            cout << "\n";
            cout << "Soldier #" << i << "\n";
            report(platoon[i - 1]);
            cout << "\n";
            break;
        }
    
        cout << "error! need a number between 1 and " << platoon.size() << "\n";
        cout << "\n";
    }

    // sort by serial number (using function)
    sort(platoon.begin(), platoon.end(), SortBySerialNumber);

    cout << "Soldiers ordered by serial number:\n";
    for(size_t i = 0; platoon.size() > i; ++i) {
        report(platoon[i]);
    }
    cout << "\n";

    // sort by name (using predicate object)
    sort(platoon.begin(), platoon.end(), SortByName());

    cout << "Soldiers ordered by name:\n";
    for(size_t i = 0; platoon.size() > i; ++i) {
        report(platoon[i]);
    }
    cout << "\n";

    return 0;
}

void PreFillVector(vector<Soldier>& platoon)
{
    Soldier soldier;

    soldier.name = "Walker";
    soldier.rank = "Private";
    soldier.serialNumber = 194032;
    platoon.push_back(soldier);

    soldier.name = "Mainwaring";
    soldier.rank = "Captain";
    soldier.serialNumber = 194055;
    platoon.push_back(soldier);

    soldier.name = "Pike";
    soldier.rank = "Private";
    soldier.serialNumber = 194018;
    platoon.push_back(soldier);

    soldier.name = "Wilson";
    soldier.rank = "Sergeant";
    soldier.serialNumber = 194053;
    platoon.push_back(soldier);

    soldier.name = "Jones";
    soldier.rank = "Lance-Corporal";
    soldier.serialNumber = 194070;
    platoon.push_back(soldier);
}


Enter soldier details (use "exit" for name to finish.)

Soldier name? Winsu
Soldier rank? Colonel
Soldier serial number? 100000

Soldier name? Andy
Soldier rank? Lieutenant
Soldier serial number? 196410

Soldier name? exit

Soldiers (unsorted):
Walker    , Private       , 194032
Mainwaring, Captain       , 194055
Pike      , Private       , 194018
Wilson    , Sergeant      , 194053
Jones     , Lance-Corporal, 194070
Winsu     , Colonel       , 100000
Andy      , Lieutenant    , 196410

Which soldier do you want to show (1-7)? 9
error! need a number between 1 and 7

Which soldier do you want to show (1-7)? 6

Soldier #6
Winsu     , Colonel       , 100000

Soldiers ordered by serial number:
Winsu     , Colonel       , 100000
Pike      , Private       , 194018
Walker    , Private       , 194032
Wilson    , Sergeant      , 194053
Mainwaring, Captain       , 194055
Jones     , Lance-Corporal, 194070
Andy      , Lieutenant    , 196410

Soldiers ordered by name:
Andy      , Lieutenant    , 196410
Jones     , Lance-Corporal, 194070
Mainwaring, Captain       , 194055
Pike      , Private       , 194018
Walker    , Private       , 194032
Wilson    , Sergeant      , 194053
Winsu     , Colonel       , 100000

Last edited on
heheeehe, what a nice example mate!!!,

Thanks so much, I'll have a deep look on that...my level in c++ is not so large, I know what STL libraries contains, but not so much further than that....I'm on using them properly...
I have understood perfectly how I could do that using sort function for structs.

now , I trying to use it with class composed by vector...It's giving me a hard time...because I cant use an iterator for an object composed by vector which cover all of them...

I'm doing something like that:

relevant code...

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43

class bench{
	private:
		vector<string> name;
		vector<int>  stock;
		vector<int> order;
		vector<int> day;
		vector<int> month;
		vector<int> year;
public:

	bool sortbyorder(const bench&,const bench&);
	void ShowWholeInformation( const bench& ratula);

};
void bench::ShowWoleInformation(const bench& ratula){
		
		for(vector<string>::iterator in = name.begin();in != name.end();
		vector<int>::iterator is = stock.begin();is !=stock.end();vector<int>::iterator io = order.begin();io !=order.end();
		++in;++is;++io){
			cout<<*in;
			cout<<" ";
			cout<<*is;
			cout<<" ";
			cout<<*io;
		}
	}
	
	
	bool  bench::sortbyorder(const bench& lhs, const bench& rhs){     
    return (lhs.order < rhs.order);
	
	}

int main(int argc, char **argv)
{
cout<<"PCB ordered by order amount:";
	sort(ratula.begin(),ratula.end(),sortbyorder);
	ShowWoleInformation(ratula);
}





I dont know If I can iterate an object and take the information of any vector that I want with te same iterator,I though that I had to set an iterator for each vector,but class bench doesnt have end,begin functions, so or I cant or I should have to do them(begin,end), and I think It must be quite difficult...

or maybe using templates...???I dont know, any iluminating idea :)
I'm not sure you want to do, but if you're trying to step all iterators in parallel you will need to adjust the for( ; ; ) so it:
- initializes all variables
- tests all variable (safely!)
- steps all

Remember that it's:

for (initialization; condition; increase) statement;

from:
http://www.cplusplus.com/doc/tutorial/control/

That is, one initialization statement, one condition, and one increase statement. But these can be compound statements (including those using operator, -- the comma or sequence operator)
http://www.cplusplus.com/doc/tutorial/operators/

But this is pretty a good example of why you should use a vector of structs rather than parallel vectors of basic types! It'll look pretty ugly!!

Andy
Last edited on
I think I'm getting an error because I'm addresing iterator to vector which belong to a class, and It just get the first iterator..I know It's strange to do, but I would like to achieved it like that..

1
2
3
4
5
6
7
8
9
10
11
12
13
	void bench::ShowWholeInformation(const bench& ratula){
		
		for(vector<string>::iterator bench::in = name.begin();vector<int>::iterator is = stock.begin();
		vector<int>::iterator io = order.begin();in != name.end();is !=stock.end();io !=order.end();
		++in;++is;++io){
			cout<<*in;
			cout<<" ";
			cout<<*is;
			cout<<" ";
			cout<<*io;
		}
	}



and trying this the same situation..some part of the compiler says If I relaxed the compiler rules It would accep it...

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
class bench{
	private:
		vector<string> name;
		vector<int>  stock;
		vector<int> order;
		vector<int> day;
		vector<int> month;
		vector<int> year;
		
void bench::ShowWholeInformation(const bench& ratula){
		
		for(vector<string>::iterator bench::in = bench::name.begin();vector<int>::iterator bench::is = bench::stock.begin();
		vector<int>::iterator io = order.begin();in != name.end();is !=stock.end();io !=order.end();
		++in;++is;++io){
			cout<<*in;
			cout<<" ";
			cout<<*is;
			cout<<" ";
			cout<<*io;
		}
	}




I dont know why I cant do a for with three iterators...I think It is because the vector belong to a class, and the class doesnt have begin and end function, should I define the functions for thr prooouse??
I know It's strange to do, but I would like to achieved it like that..

But you can't. As I said before, the form of the for statement is:

for (initialization; condition; increase) statement;

YOU ARE ONLY ALLOWED TWO SEMICOLONS!!! (not 8)

You can achieve what you want if you use the comma operator (which I mentioned last time as well.)

But it's an UGLY way to do it!!

Andy
Last edited on
Know I get it, sorry I need more vocabulary in english about this....

But It doesnt work yet...sorry if Im being tiresome...

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39

class bench{
	private:
		vector<string> name;
		vector<int>  stock;
		vector<int> order;
		vector<int> day;
		vector<int> month;
		vector<int> year;
		
public:
	
		void CopyName(string boardname);
		void CopyStock(int amountboard);
		void ShowCopyName();
		void ShowCopyStock();
		void ShowNameBoard();
		void ShowBoardStock(int a);
		void CopyDate();
		void CopyOrder();
		int ShearchingMaximunOrder();
		bool sortbyorder(const bench&,const bench&);
		void ShowWholeInformation( const bench& ratula);
	};
	
	void bench::ShowWholeInformation(const bench& ratula){
		
		for(vector<string>::iterator in = name.begin(),vector<int>::iterator is = stock.begin(),
		vector<int>::iterator io = order.begin();in != name.end(),is !=stock.end(),io !=order.end();
		++in,++is,++io){
			cout<<*in;
			cout<<" ";
			cout<<*is;
			cout<<" ";
			cout<<*io;
		}
	}
	



the compilered says:one of them invalid declaration of 'std::vector<int>::iterator....
Hi,

I have done that with a struct, and It's working,but what I would like to do now is getting the object(any bench) with the maximum order...

I have tryed with this function..

http://www.cplusplus.com/reference/algorithm/max_element/

But It's not working since what I have to address is what is the maximun order in differents object...and I can addres a vector with .begin() AND end(), but I cant imagine how to address a vector of struct to know the position of the maximum order and get that object and show it with the show function...

Here is my code

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
#include <stdio.h>
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>

using namespace std;

struct bench{

		string name;
		int  stock;
		int order;
	};	
		
		
	bench CopyInformation(bench a){
		const string exit_cmd = "exit";
		string name;
		int order;
		int stock;
		while(name != exit_cmd) {
        cout << "Board name? ";
        getline(cin, name);
        if(!name.empty() && (name != exit_cmd)){
            cout<< "Board stock? ";
            cin >> stock;
            cout << "Board Order ";
            cin >> order;
            cin.ignore();
			a.name = name;
            a.stock= stock;
            a.order = order;
		
        }
        cout << "\n";
		}
		return a;	
	}
	
	bool SortByOrder(const bench& lhs, const bench& rhs){     
		return (lhs.order < rhs.order);
	}
	
	void FillWorkShop(vector<bench>& WorkShop){
		 bench newoperator;

    newoperator.name = "PCB185";
    newoperator.order = 152;
    newoperator.stock = 356;
    WorkShop.push_back(newoperator);

	newoperator.name = "PCB124";
    newoperator.order = 56;
    newoperator.stock = 23;
    WorkShop.push_back(newoperator);
	
	newoperator.name = "PCB500";
    newoperator.order = 456;
    newoperator.stock = 2265;
    WorkShop.push_back(newoperator);
	
	newoperator.name = "PCB326";
    newoperator.order = 7;
    newoperator.stock = 456;
    WorkShop.push_back(newoperator);
	
	newoperator.name = "PCB236";
    newoperator.order = 78;
    newoperator.stock = 99;
    WorkShop.push_back(newoperator);

   }
	
	
		
	
	
	void ShowBoards(const bench& s) {
    cout << left
         <<"Name: "  << s.name << ", "
         <<"Stock: "  << s.stock << ", "
         <<"Order: "  << s.order << "\n";
}
	

	

int main(int argc, char **argv)
{
	vector<bench> WorkShop;
	bench newoperator;
	newoperator = CopyInformation(newoperator);
	WorkShop.push_back(newoperator);
	FillWorkShop(WorkShop);
	sort(WorkShop.begin(),WorkShop.end(),SortByOrder);
	cout<< "Sort by Order Number"<< "\n";
	for(size_t i = 0; i != WorkShop.size();i++){
		ShowBoards(WorkShop[i]);
		}
		cout<<"\n";
	
	cout << "Board Information of Maximun Order"<<"\n";

	
	}

but I cant imagine how to address a vector of struct to know the position of the maximum order and get that object and show it with the show function...

You call max_element in the same way as you called sort. In fact, you can use exactly the same comparison function that you use for the sorting as it works with the required member of your struct (the order.)

But max_element returns an iterator to the maximum element, if it found one, or end() of your vector it it didn't (because the vector was empty.)

1
2
3
4
5
6
7
8
9
    vector<bench>::iterator iter = max_element(WorkShop.begin(),WorkShop.end(),SortByOrder);
    if(iter == WorkShop.end()) {
        cout << "Could not find maximum order\n";
    } else {
        bench& benchMax = (*iter); // dereference iterator to obtain bench
        cout << "Board Information of Maximun Order"<<"\n";
        ShowBoards(benchMax);
        cout<<"\n";
    }


But as you've sorted your vector by order size, the last element will have the maximum value, so you could just access it directly using vector's back() method.
http://www.cplusplus.com/reference/vector/vector/back/

Of course, back() should only be used if the vector isn't empty.

And neither the max_element() nor back() approach deal with multiple orders having the same, maximum order value.

Andy

PS You names aren't as clear as they might be!?
Last edited on
Thanks so much...I didnt realize that It could be address in the same...

Thanks for the clarification,I'm learning because of you!!
Using parallel vectors.

Your problem was dealing with the comma operator.

1. When intializing multiple variable using the comma operator, all variables must be of the same type.

vector<int>::iterator is = stock.begin(), io = order.begin();

This is OK, as is and io are both vector<int> iterators.

But as one of your iterators was different, it couldn't be done. See code below for a way around the problem.

2. in your termination condition, as the comma operator returns the result obtained by the evaluation of the rightmost expression,

in != name.end(), is !=stock.end(), io !=order.end()

just looks like this

io !=order.end()

so your code won't spot if the other two vectors have run out of elements earlier than expected.

The code below should work.

But it's still a bad idea!

Andy

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
#include <iostream>
#include <string>
#include <vector>
using namespace std;

class bench{
private:
    vector<string> name;
    vector<int> stock;
    vector<int> order;
    vector<int> day;
    vector<int> month;
    vector<int> year;
public:
    // for testing
    void AddOrder(string n, int s, int o, int d, int m, int y);
    // method to test
    // no need for const bench& ratula parameter?
    void ShowWholeInformation();
};

void bench::AddOrder(string n, int s, int o, int d, int m, int y){
    name.push_back(n);
    stock.push_back(s);
    order.push_back(o);
    day.push_back(d);
    month.push_back(m);
    year.push_back(y);
}

// no need for const bench& ratula parameter?
void bench::ShowWholeInformation(){
    // due to the way operator= works, you need to define
    // and initialize all the iterator variable befor the
    // for() loop begins.
    vector<string>::iterator in = name.begin();
    vector<int>::iterator is    = stock.begin();
    vector<int>::iterator io    = order.begin();
    vector<int>::iterator id    = day.begin();
    vector<int>::iterator im    = month.begin();
    vector<int>::iterator iy    = year.begin();
    // start off by initializing all iterators to begin()
    // of corresponding vector
    for( /*iterators already defined and initialized */ ;
         // use && not , (comma) to check that none of
         // iterators has reached the end of their array
         in != name.end() && is != stock.end() && io !=order.end() &&
         id != day.end()  && im != month.end() && iy !=year.end();
         // increment all iterators
         ++in,++is,++io, ++id, ++im, ++iy ){
        // output basic info
        cout<<*in;
        cout<<" ";
        cout<<*is;
        cout<<" ";
        cout<<*io;
        cout<<" ";
        // output date
        cout<<*id;
        cout<<"/";
        cout<<*im;
        cout<<"/";
        cout<<*iy;
        cout<<"\n";
    }
}

int main()
{
    bench b;

    b.AddOrder("PCB185",  356, 152, 15, 5, 2015);
    b.AddOrder("PCB124",   23,  56, 16, 5, 2015);
    b.AddOrder("PCB500", 2265, 456, 16, 5, 2015);
    b.AddOrder("PCB326",  456,   7, 17, 5, 2015);
    b.AddOrder("PCB236",   99,  78, 18, 5, 2015);

    b.ShowWholeInformation();

    return 0;
}
Last edited on
Ok, the trouble was that char is longer than int, so It couldn't be done because vector<int> finish before than vector<string>....that's so logic...but I didnt expect that the compiler could know that...


But while It's carry on showing the vector<string>(because is longer),in thh same time It's showing "rubish" from the rest vector<int>,isnt it? or at least is how I understand it..., because until they dont get their ends, the iterators will be increased......but as they have got their tops, the cant show anything, because an iterator cant make longer the size, I'm in doubt with this....


-and now I was trying to get a code to spot if in any objet has a oder with 0 value, stock with 0 value and a name with " "


once I get the iterator which point one of them I cant remove it with the erase function, but I cant spot that at the moment....I'm trying this...

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
void EraseCeroValue(vector<bench> WorkShop){
				int count = 0;
	for( vector<bench>::iterator it = WorkShop.begin();it != WorkShop.end();++it){
				 bench& benchErase = (*it);
				
				 if(order.benchErase = 0 or stock.benchErase = 0 or name.benchErase = " "){
					 WorkShop.erase (WorkShop.begin()+count);
				 }
				 ++count;
				
			
		}





This code comes from struct bench not class bench...





Pages: 12