ex4_19.cpp

来自「Visual C++ 2005的源代码」· C++ 代码 · 共 33 行

CPP
33
字号
// Ex4_19.cpp : main project file.
// Creating and using interior pointers

#include "stdafx.h"

using namespace System;

int main(array<System::String ^> ^args)
{
  // Access array elements through a pointer
  array<double>^ data = {1.5, 3.5, 6.7, 4.2, 2.1};
  interior_ptr<double> pstart = &data[0];
  interior_ptr<double> pend = &data[data->Length - 1];
  double sum = 0.0;
  while(pstart <= pend)
    sum += *pstart++;
  
  Console::WriteLine(L"Total of data array elements = {0}\n", sum);

  // Just to show we can - access strings through an interior pointer
  array<String^>^ strings = { L"Land ahoy!",
                             L"Splice the mainbrace!",
                             L"Shiver me timbers!",
                             L"Never throw into the wind!"
                           };
  
  for(interior_ptr<String^> pstrings = &strings[0] ;
             pstrings-&strings[0] < strings->Length ; ++pstrings)
    Console::WriteLine(*pstrings);

  return 0;
}

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?