cout << armor []?

Hey. How would my code be if:
I want all my "armor" variables to be in an own cout, like that if a new "armor" variable is created it will be printed?

1
2
3
4
5
int armor [];
int main ()
    {
    cout << armor [] (?) << endl;
    }


Tell me if you dont understand :)
I think I understand, but I'm not sure.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
#include <iostream>

class Armor
{
public:

    Armor() { std::cout << "new armor created!" << std::endl; }
};

int main()
{
    Armor my_armor;
    Armor more_armor;
    Armor yet_more_armor;
}
new armor created!
new armor created!
new armor created!

If you have trouble explaining what you want, just
write what you want the code and output to look like.
Hm, I mean like:

1
2
3
4
5
6
7
8
#include <iostream>
using namespace std;

int armor [] = { 1, 2, 4, 8 };
int main;
{
    cout << "Armor:" << armor [] << endl;
}


so that all armor chars will be printed on a new line. I dont wanna repeat the "cout" line because its supposed to show the other armors if they are created.

Armor: 1
Armor: 2
Armor: 4
Armor: 8
Last edited on
Ok, then. What you need is a for loop -> http://cplusplus.com/doc/tutorial/control/#for
Topic archived. No new replies allowed.