-4

When I use the following code I get a mem address(?) before the second item of the pair like this: 666, 0x6090e8667 666, 0x6090e8667 666, 0x6090e8667.

What am I doing wrong?

std::vector<std::vector<std::vector<std::pair<int,int> > > > total;

int main()
{

  total.resize(10);
  for (int i = 0; i < 10; ++i)
    {
      total[i].resize(10);
    }

  for (int i = 0; i < 10; i++)
    {
      total[0][0].push_back(std::make_pair(666,667));
    }

  for (int i=0; i<3; i++)
    {
      std::cout << total[0][0][i].first << ", " <<
      std::cout << total[0][0][i].second << '\t';
    }
  std:: cout << std::endl;

}
Brian Tompsett - 汤莱恩
  • 5,753
  • 72
  • 57
  • 129
Charis Ch
  • 1
  • 1

3 Answers3

3
std::cout << total[0][0][i].first << ", " <<
std::cout << total[0][0][i].second << '\t';

Due to the << at the end of the first line, you're outputting std::cout (in the second line) into cout, as if you typed std::cout << std::cout;. Apparently your compiler has an overload or conversion that causes this to display a memory address (although it may fail to compile on other compilers).

Either replace it with a semicolon, or remove the std::cout << from the second line.

interjay
  • 107,303
  • 21
  • 270
  • 254
0

For

std::cout << total[0][0][i].first << ", " <<

you probably meant

std::cout << total[0][0][i].first << ", ";
Simo Erkinheimo
  • 1,347
  • 9
  • 17
0

You have used std::cout << total[0][0][i].first << ", " <<. The extra << at the end of the line (and no semicolon) ends up outputting the next std::cout into your first std::cout statement.

It behaves like this: std::cout << std::cout leading to the address being displayed.

You probably wanted to use: std::cout << total[0][0][i].first << ", "; instead.

Madhav Datt
  • 1,065
  • 2
  • 10
  • 25