Printing with square brackets (vector)

I am coding in c++. i need to print a vector as output.
my output is 2 3 but the problem expects the output [2,3]
in this form. How should I print it ??

hello @nidhigupta847
u need do it using cout statements only, there is no other ways.

cout<<"[";
then print ur vector element by seperating them with comma.
and then
cout<<"]"

haha okay. I thought maybe there’s some other way which I am not aware of. Anyway thanks. :slight_smile:

Hey but then there is a comma after last element too

dont print comma after last element .
handle it with if statement.
i,e
if i !=n-1
cout<<","

1 Like