在c ++控制台应用程序中显示数组 [英] displaying array in c++ console app
本文介绍了在c ++控制台应用程序中显示数组的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我想显示一个不使用循环的数组(for,while ......)类似的东西:
Hi,
I want to display an array without using loop(for, while ...) something like it:
int arr[10];
std::cout<<arr;
但它给出了一个数字。
现在我正在使用下面的代码:
But it gives a number.
right now im using the code bellow:
for(int i=0;i<10;i++)
std::cout<<arr[i]
有没有办法像第一个那样做?
谢谢,
is there any way to do it like the first one?
Thank you,
推荐答案
例如,下面的代码示例演示了如何在没有循环的情况下打印数组:
For example the following code example demonstrates how to print array without loop:
#include <iostream>
#include <iterator>
#include <algorithm>
using namespace std;
int main()
{
short arr[] = { 10, 20, 30, 40 };
copy(arr,arr + sizeof(arr) / sizeof(arr[0]),ostream_iterator<short>(cout,"\n"));
}
嗨亲爱的朋友
以下代码可以显示你的字符串,没有任何循环:
hi dear friend
with below code you can display your string without any loop:
<pre lang="c++">
char a[5]="hello";
printf("%s",a);
这篇关于在c ++控制台应用程序中显示数组的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文