Printing a vector

I have some trouble printing a vector. I tried printf and cout but no luck so far.

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
 
struct car

{
	
string marka;

string model;

int obujam;

int masa;

int max_snaga_kw;

int max_snaga_ks;

int max_brzina;

float ubrzanje;

};



vector<car> allcars(56); 

 allcars[0] = { "AUDI", "R8 SPYDER", 5204, 1720, 386, 535, 313, 4.1 };



printf ("%s", allcars[0].marka);


It say: [Error] cannot pass objects of non-trivially-copyable type 'std::string {aka class std::basic_string<char>}' through '...'

Thanks in advance.
You should use the iostream library. You can start here:
http://www.cplusplus.com/doc/tutorial/files/

Then you can read this one. It covers what you really need for this issue.
https://www.cprogramming.com/tutorial/c++-iostreams.html
Last edited on
I am sorry but i did not understand that article what so ever. If you could give me an example maybe i will understand.
printf ("%s", allcars[0].marka);
printf knows how to print char *, so this should do: printf ("%s", allcars[0].marka.c_str()
It is compiled there is just one new problem.
C:\Users\korisnik\Desktop\Dream cars 2.0.cpp In function 'int main()':
And when i double click it, it goes to the first #include. Even if I reshuffle them or erase the first one. It always goes to the first one. And when I try to run it I get: Error 87: The parameter is incorrect.
you didnt post the main function, so we can't tell you what is wrong with it.
unless its missing.
c++ programs need a starting point, and that starting point is defined as int main() always.

without it, you can still compile as a library or something but it can't run and you need different compiler switches for that.

Last edited on
This is my whole program so far

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
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
#include <cstdio>
#include <iostream>
#include <windows.h>
#include <conio.h>
#include <fstream>
#include <stdlib.h>
#include <time.h>
#include <queue>
#include <setjmp.h>
#include <vector>

using namespace std;

int car0, car1, car2, car3, car4, car5, car6, car7, car8, car9, car10, car11, car12, car13, car14, car15, car16, car17, car18, car19, car20, car21, car22, car23, car24, car25, car26, car27, car28, car29, car30, car31, car32, car33, car34;

int car35, car36, car37, car38, car39, car40, car41, car42, car43, car44, car45, car46, car47, car48, car49, car50, car51, car52, car53, car54, car55;

queue<int> player;

queue<int> bot;

queue<int> game;

int robot();

int x, z;

jmp_buf h;

struct car

{
	
string marka;

string model;

int obujam;

int masa;

int max_snaga_ks;

int max_brzina;

float ubrzanje;

};

int main()

{

vector<car> allcars(56); 

allcars[0] = { "AUDI", "R8 SPYDER", 5204, 1720, 535, 313, 4.1 };

allcars[1] = { "JAGUAR", "XKR", 5000, 1755, 510, 250, 4.8 };

allcars[2] = { "SUBARU", "IMPEREZA WRX STI", 2457, 1450, 300, 250, 5.2 };

allcars[3] = { "BMW", "M3", 3999, 1605, 420, 250, 4.8 };

allcars[4] = { "ASTON MARTIN", "DB9", 5935, 1710, 450, 300, 4.9 };

allcars[5] = { "ASTON MARTIN", "ONE 77", 7312, 1500, 730, 320, 4 };

allcars[6] = { "AUDI", "LE MANS QUATTRO", 4961, 1570, 610, 345, 3.7 };

allcars[7] = { "CHEVROLET", "CORVETTE SUPERCHARGED ZR1", 6162, 1510, 647, 330, 3.6 };

allcars[8] = { "BUGATTI", "VEYRON EB", 7993, 1890, 1001, 407, 2.5 };

allcars[9] = { "LOTUS", "ELISE 111R", 1796, 850, 192, 220, 5 };

allcars[10] = { "BRABUS", "G 6.3 SV12 BITURBO", 6300, 2400, 610, 240, 4.7 };

allcars[11] = { "PORSCHE", "911 CARRERA", 3596, 1440, 320, 280, 5.5 };

allcars[12] = { "PORSCHE", "CARRERA GT", 5733, 1380, 612, 330, 3.9 };

allcars[13] = { "AUDI", "R8 GT", 5204, 1525, 560, 320, 3.6 };

allcars[14] = { "MAZDA", "RX-8", 2*654, 1345, 240, 235, 6.4 };

allcars[15] = { "FERRARI", "612 SCAGLIETTI", 5748, 1840, 540, 315, 4.2 };

allcars[16] = { "LAMBORGHINI", "GALLARDO LP570 SUPERLEGGERA", 5204, 1340, 570, 325, 3.4 };

allcars[17] = { "DODGE", "RAM SRT-10", 8277, 2275, 506, 249, 5.6 };

allcars[18] = { "LAMBORGHINI", "REVENTON", 6496, 1665, 650, 340, 3.4 };

allcars[19] = { "DODGE", "VIPER SRT-10", 8277, 1545, 506, 306, 3.9 };

allcars[20] = { "MASERATI", "COUPE", 4244, 1670, 390, 284, 4.8 };

allcars[21] = { "ALFA ROMEO", "3.2 V6 24V GT", 3179, 1455, 240, 243, 5.7 };

allcars[22] = { "MERCEDES", "CL 65 AMG", 5980, 2165, 612, 250, 4.4 };

allcars[23] = { "FERRARI", "FIORANO 599 GTB", 5999, 1690, 620, 330, 3.7 };

allcars[24] = { "PORSCHE", "PANAMERA", 4806, 1970, 500, 303, 4.2 };

allcars[25] = { "ASTON MARTIN", "VANQUISH", 5935, 1835, 466, 306, 4.8 };

allcars[26] = { "DODGE", "CHALLENGER SRT 8", 6059, 1569, 431, 270, 5.1 };

allcars[27] = { "CHEVROLET", "CORVETTE C5", 5665, 1455, 355, 281, 5.1 };

allcars[28] = { "ASTON MARTIN", "RAPIDE", 5935, 1950, 477, 303, 5.3 };

allcars[29] = { "MITSUBISHI", "LANCER EVOLUTION VIII", 1997, 1470, 265, 245, 6.1 };

allcars[30] = { "LAMBORGHINI", "GALLARDO", 4961, 1530, 500, 309, 4.2 };

allcars[31] = { "FORD", "FOCUS RS 500", 2521, 1390, 350, 263, 5.6 };

allcars[32] = { "PORSCHE", "911 GT 2 RS", 3600, 1370, 620, 330, 3.5 };

allcars[33] = { "BMW", "M5", 4999, 1830, 500, 250, 4.7 };

allcars[34] = { "MUSTANG", "GT", 4606, 1565, 304, 240, 6.2 };

allcars[35] = { "DODGE", "VIPER SRT 10 (RACING EDITION)", 8360, 1560, 612, 310, 4.1 };

allcars[36] = { "MORGAN", "AERO SUPERSPORTS", 4799, 1175, 367, 273, 4.5 };

allcars[37] = { "FERRARI", "ENZO", 5998, 1365, 660, 350, 3.65 };

allcars[38] = { "OPEL", "SPEEDSTER TURBO", 1998, 930, 200, 243, 4.9 };

allcars[39] = { "HONDA", "3.2 V6 TEC", 5204, 1720, 535, 313, 4.1 };

allcars[40] = { "marka40", "model40", 5204, 1720, 535, 313, 4.1 };

allcars[41] = { "marka41", "model41", 5204, 1720, 535, 313, 4.1 };

allcars[42] = { "marka42", "model42", 5204, 1720, 535, 313, 4.1 };

allcars[43] = { "marka43", "model43", 5204, 1720, 535, 313, 4.1 };

allcars[44] = { "marka44", "model44", 5204, 1720, 535, 313, 4.1 };

allcars[45] = { "marka45", "model45", 5204, 1720, 535, 313, 4.1 };

allcars[46] = { "marka46", "model46", 5204, 1720, 535, 313, 4.1 };

allcars[47] = { "marka47", "model47", 5204, 1720, 535, 313, 4.1 };

allcars[48] = { "marka48", "model48", 5204, 1720, 535, 313, 4.1 };

allcars[49] = { "marka49", "model49", 5204, 1720, 535, 313, 4.1 };

allcars[50] = { "marka50", "model50", 5204, 1720, 535, 313, 4.1 };

allcars[51] = { "marka51", "model51", 5204, 1720, 535, 313, 4.1 };

allcars[52] = { "marka52", "model52", 5204, 1720, 535, 313, 4.1 };

allcars[53] = { "marka53", "model53", 5204, 1720, 535, 313, 4.1 };

allcars[54] = { "marka54", "model54", 5204, 1720, 535, 313, 4.1 };

allcars[55] = { "marka55", "model55", 5204, 1720, 535, 313, 4.1 };

printf ("%s", allcars[0].marka.c_str());

return 0;

}


and yes I need everything that is in there between using namespace std; and struct.
after removing the thankfully unused windows and dos headers and the h variable & jump buf header, it compiled and ran in the forum's online compiler.

so if it isnt working, its a problem with jump-buf or your compiler/project settings.

and knock off the printf.
#include<iostream>
std::cout << allcars[0].marka;

printf is good for printing a bunch of doubles of varying formats and sprintf is occasionally useful if you get stuck with a char* from a library. Otherwise, use strings and streams.

Last edited on
It would help if you copy-pasted the exact error message, with the filename+line numbers each error refers to.
It is solved thanks for the help.
Topic archived. No new replies allowed.