referencing in the loop

My problem is as following.
I have an 2 arrays named: abee1 , abee2.
I have loop that want to call them one by one and print data of an them in each step.
It means that I want to reach the name of arrayBee1 to arrayBee2 in the loop for printing its data. I made the name of each one by using strings ( abee1 , abee2) in the loop.


1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
        #include<iostream>
        #include<string>
        #include <sstream>
        using namespace std ;
        
        int abee1 [4] [4] = {{5,0,40,30},{6,0,21,47},{7,0,17,63},{8,0,31,62}};
        int abee2 [4] [4] = {{1,0,37,52},{2,0,49,49},{3,0,52,64},{4,0,20,26}};
        int main()
        {		
        	int cc;
        	for ( cc = 1 ; cc < 3; cc++)
             // making the name of nbee1 and nbee2    			
                    {	string String = static_cast<ostringstream*>( &( ostringstream () << cc) )->str();
        				string arrayname = "abee" + String;
             // using pointer to have the values of nbee1 or nbee2
        				string *a = & arrayname;
        				for ( cc = 0 ; cc < 4; cc++)
        					cout << *a<<"\n";
        			}
        return 0;
        }


I know something is wrong with the "string *a = & arrayname;" part of code and after that.
Please help me to fix it.
Last edited on
What's all the magic with the ostringstream? Why not just something like:
1
2
3
4
5
6
for(unsigned int i = 0; i < 4; ++i) {
    for(unsigned int j = 0; j < 4; ++j) {
        std::cout<<"abee1["<<i<<"]["<<j<<"] = "<<abee1[i][j]<<"\n";
        std::cout<<"abee2["<<i<<"]["<<j<<"] = "<<abee2[i][j]<<"\n";
    }
}
Thank you Zhuge.
But it is not my original program. I used print instead of copying an array into abee1 and abee2. Then I really need making these name by string which can refer to the abee1 and abee2.
Topic archived. No new replies allowed.