Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/arrays/14.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C++ 如何通过指针数组进行重复?_C++_Arrays_C++11_Pointers - Fatal编程技术网

C++ 如何通过指针数组进行重复?

C++ 如何通过指针数组进行重复?,c++,arrays,c++11,pointers,C++,Arrays,C++11,Pointers,我的程序应该只使用一个指针在数组中迭代几个小时 for (int i = 0; i < totalHours; i++) { cout << " " << i + 1; while (ptrSvr <= last) { rand_set(ptrSvr); print(ptrSvr); ptrSvr++; } cout << endl; } return 0;

我的程序应该只使用一个指针在数组中迭代几个小时

for (int i = 0; i < totalHours; i++)
{
    cout << " " << i + 1;
    while (ptrSvr <= last)
    {
        rand_set(ptrSvr);
        print(ptrSvr);
        ptrSvr++;
    }
    cout << endl;
}

return 0;
这就是打印的功能

 void print(int* ps)
 {
     cout << "       " << *ps << " ";
 }
void打印(int*ps)
{

如果你有

int arr[]={}

然后


之后,while
循环将重置它。否则,您必须存储
ptrSvr
的第一个值,并在
之后重置它,while

循环退出
时,代码没有足够的上下文。如何设置
ptrSvr
last
的值。这取决于有不同的方法。@MarekR我添加了其余的内容你是否确定你在C++类中?它看起来更像是学习C,只使用代码> Prtff<代码>和<代码> MalOC/<代码>被<代码> CUT< /COD>和<代码>新< /代码>取代。无论如何,请提供一个实际的,即可以直接复制和编译的东西。
 void print(int* ps)
 {
     cout << "       " << *ps << " ";
 }
void initialize(int ts, int* &ps, int* &pt,
                int* &l, int* &ha)
{
    for (int i = 0; i < ts; i++)
    {
        ps[i] = 0;
        pt[i] = 0;
        l = &ps[i];
    }

    ha = NULL;
    srand(time(NULL));
}
// Pointer declarations          
int *ptrSvr;                // Po
int *ptrTotal;              // Po
int *last;                  // Po
int *highestAttempts;       // Po

// Variable declarations         
int totalServers;           // Va
int totalHours;             // Va
int total;                  // Va

// Prompt user for number of serv
// totalServers and totalHours   
cout << "Enter the number of web 
cin >> totalServers;             
cout << "Enter the number of hour
cin >> totalHours;               

// Declares arrays for ptrSvr and
// of total servers              
ptrSvr = new int[totalServers];  
ptrTotal = new int[totalServers];
ptrSvr = arr;