vector in vector print

Hello I have problem with print a vector. Could you help me ?

HERE IS CODE - >
print == wyswietl

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
#include <iostream>
#include <cstdlib>
#include <vector>
#include <algorithm>
using namespace std;
/*
Pojemnik vector wypelnij interakcyjnie liczbami (int, long, float,double) - uzyj szablonu (template). 
Posortuj zawartosc od najmniejszej do najwiekszej metoda babelkowa.
*/


template <typename T>
class unknown_t
{
	public:
	vector<T> liczba;
	vector<unknown_t<T> > my_vector;
	
    void wstaw(int i,unknown_t<int> &u1);
    void wstaw(long l,unknown_t<long> &u1);
    void wstaw(float f,unknown_t<float> &u1);
    void wstaw(double d,unknown_t<double> &u1);
    
    void wyswietl();
    void sortowanie();
};

template<class T>
void unknown_t<T>::wstaw(int i,unknown_t<int> &u1){
	u1.liczba.push_back(i);
	my_vector.push_back(u1);
	cout << "Dodalem liczbe : " << i <<endl;
}
template<class T>
void unknown_t<T>::sortowanie(){


}

template<class T>
void unknown_t<T>::wstaw(long i,unknown_t<long> &u1){
	u1.liczba.push_back(i);
	my_vector.push_back(u1);
	cout << "Dodalem liczbe : " << i <<endl;
}

template<class T>
void unknown_t<T>::wstaw(float i,unknown_t<float> &u1){
	u1.liczba.push_back(i);
	my_vector.push_back(u1);
	cout << "Dodalem liczbe : " << i <<endl;
}

template<class T>
void unknown_t<T>::wstaw(double i,unknown_t<double> &u1){
	u1.liczba.push_back(i);
	my_vector.push_back(u1);
	cout << "Dodalem liczbe : " << i <<endl;
}

template<class T>
void unknown_t<T>::wyswietl(){
	typename std::vector<unknown_t<T> >::iterator It1;
	It1 = my_vector.begin();
	for ( It1 = my_vector.begin( ) ; It1 != my_vector.end( ) ; ++It1 )
	cout << " " << *It1<<endl;
	
}

main(){
	unknown_t<int> u1;
	unknown_t<long> u2;
	unknown_t<float> u3;
	unknown_t<double> u4;
	int petla=1;
	int wybor;
	int liczba;
	while(petla){
	
	cout << "M E N U " << endl;
	cout << "^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^" << endl << endl;
	cout << "1. Dodaj int"  << endl;
	cout << "2. Dodaj long"  << endl;
	cout << "3. Dodaj float"  << endl;
	cout << "4. Dodaj double"  << endl;
	cout << "5. Posortuj" << endl;
	cout << "6. SORTOWANIE" << endl;
	cout << "^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^" << endl << endl;
	
	cout << "Co chcesz zrobic ? " << endl;
	cin >> wybor;
	
		switch(wybor){
			case 1:
				cout << "Jaka liczbe chcesz dodac ? " << endl;
				cin >> liczba;
				u1.wstaw(liczba,u1);
				break;
			case 2:
				cout << "Jaka liczbe chcesz dodac ? " << endl;
				cin >> liczba;
				u2.wstaw(liczba,u2);
				break;
			case 3:
				cout << "Jaka liczbe chcesz dodac ? " << endl;
				cin >> liczba;
				u3.wstaw(liczba,u3);
				break;
			case 4:
				cout << "Jaka liczbe chcesz dodac ? " << endl;
				cin >> liczba;
				u4.wstaw(liczba,u4);
				break;
			case 5:
				u1.wyswietl();
				break;
			case 6:
				u1.sortowanie();
				break;
		}
	}
	
	
	system("PAUSE");
	return 0;
}
Last edited on
Please do not show all your long code listing. Say what is the problem of printing a vector? I think you understand that to output a vector in a stream its elements also should be outputed. That is if you have a vector

std::vector<T> v;

then the operation

T x;

std::cout << x;

shall be well formed.

EDIT:
The simplest way to output the whole vector is

1
2
for ( const auto &x : v ) std::cout << x << ' ';
std::cout << std::endl;
Last edited on
Topic archived. No new replies allowed.