Displaying a table in C++
Solved
alena20
Posted messages
24
Status
Member
-
alena20 Posted messages 24 Status Member -
alena20 Posted messages 24 Status Member -
Hello,
I have a problem displaying the array:
#include <iostream>
using namespace std;
int main()
{
int Array [3]={1,2,3};
cout << Array << endl;
}
And I received the result: 0x7fff6242abf0
Thank you in advance!
Best regards,
Alena
I have a problem displaying the array:
#include <iostream>
using namespace std;
int main()
{
int Array [3]={1,2,3};
cout << Array << endl;
}
And I received the result: 0x7fff6242abf0
Thank you in advance!
Best regards,
Alena
1 answer
-
Hello, it seems to me that cout cannot display an entire array unless it is a char array (correct me if I'm wrong), you need to display element by element with, for example:
for (i=0; j<2; j++){ cout << Tableau[i]; }-
-
Thank you! Indeed. But I found the code that can be useful in some cases, based on the vector:
// ostream_iterator example
#include <iostream> // std::cout
#include <iterator> // std::ostream_iterator
#include <vector> // std::vector
#include <algorithm> // std::copy
int main ()
{
std::vector<int> myvector;
int str1[]={1, 2, 3};
myvector.assign (str1,str1+3);
std::ostream_iterator<int> out_it (std::cout,", ");
std::copy ( myvector.begin(), myvector.end(), out_it );
return 0;
}
-