如何在 for 循环内暂停

How can I pause inside a for loop

本文关键字:暂停 循环 for      更新时间:2023-10-16

好吧,我可以暂停,问题是我所有的"暂停"都是累积的,而不是按顺序完成的。我尝试了很多时钟的东西,睡觉,..每次的结果都一样。我在这里错过了什么吗?我只是想这样做来帮助我进行可视化反馈编程,它不会留在代码中,所以任何东西,即使是肮脏的,都是受欢迎的!

void Dockable::resize_cells() {
for (int i = 0; i < cells.size(); i++) {
for (int j = 0; j < cells[i].size(); j++) {
if (cells[i][j] != layout) {
if (cells[i][j]->is.docked) {
int found_col = 0;
bool found = false;
int pos = 0;
for (int k = 0; k < cells.size(); k++) {
int col = 0;
for (int l = 0; l < cells[k].size(); l++) {
if (!found) {
if (cells[i][j] == cells[k][l]) {
found = true;
pos = col;
}
}
if (!(l - 1 < 0) &&
cells[k][l] != cells[k][l - 1]) {
col++;
}
else {
col++;
}
if (found) {
if (col > found_col) {
found_col = col;
}
}
}
}       
cells[i][j]->x_size(layout->x_size() / found_col);
cells[i][j]->x((layout->x_size() / found_col) * pos);
cells[i][j]->refresh_shape_apply();
wait();
}
}
}
}
}
void Dockable::wait()
{
clock_t counter;
clock_t target;
counter = clock();
target = clock() + 100;
while (counter < target) {
counter = clock();
std::cout << counter << std::endl;
}
}

refresh_shape_apply,应用转换,因为它是在等待之前执行的,我希望它会起作用。

您可以使用此代码

system("pause");

这可能有助于暂停代码,直到您按任何字母继续。