【发布时间】:2021-04-22 04:09:54
【问题描述】:
我尝试过使用:
-
cout 我不明白它对终端做了什么。输出: On the terminal
-
cout 此解决方案将光标移至下方 22 行,这是我不想要的。
-
system('cls'); 我为它包含了 stdlib.h,但我仍然遇到同样的错误,我无法解决它。输出: On the terminal
这些是我能找到的解决方案,但它们无济于事。
这是我正在尝试的代码:
#include <iostream>
using namespace std;
void rev_array(int arr[], int start, int end)
{
while(start < end)
{
int temp = arr[start];
arr[start] = arr[end];
arr[end] = temp;
start++;
end--;
}
}
void print_array(int arr[], int size)
{
for(int i=0; i < size; i++)
cout<<arr[i]<<" ";
cout<<endl;
}
int main()
{
int n;
cout<<"Enter the size of array: ";
cin>>n;
int arr[n];
for(int i=0; i<n; i++)
cin>>arr[i];
cout<<"033[2j\033[01;1H";
print_array(arr, n);
rev_array(arr, 0, n-1);
cout<<"Reversed array is "<<endl;
print_array(arr, n);
return 0;
}
【问题讨论】:
-
许多计算机甚至没有屏幕(例如 Web 服务器)。但是您可以考虑使用像Qt 或FLTK 这样的图形工具包库。花几天时间阅读他们的文档,this C++ reference 和一些 C++ 标准,如 n3337
-
你为什么不使用C++ containers ?顺便说一句,您可能对RefPerSys 项目感兴趣......然后通过电子邮件与我联系
basile@starynkevitch.net
标签: c++ visual-studio-code vscode-code-runner