在c++中用cout输出整个字符数组:
char*p="Hello,World!";
cout<<p<<endl;//输出Hello,World!
cout<<*p<<endl;//输出H
cout<<(void*)p<<endl;
cout<<';'<<endl;//输出分号";"
扩展资料
在c++中用cout输出使用:
#include<iostream>
intmain(){
constshortITEMS=5;
intintArray[ITEMS]={1,2,3,4,5};
charcharArray[ITEMS]={'L','M','Y','L','R'};
int*intPointer=intArray;
char*charPointer=charArray;
std::cout<<"整形数组输出"<<"\n";
for(inti=0;i<ITEMS;i++){
std::cout<<*intPointer<<"at"<<intPointer<<"\n";
intPointer++;
}
std::cout<<"字符型数组输出"<<"\n";
for(inti=0;i<ITEMS;i++){
std::cout<<*charPointer<<"at"<<charPointer<<"\n";
charPointer++;
}
return0;
}
可以通过逐个输出字符数组元素的方式进行输出。
如果直接输出数组名,系统默认以字符串方式输出,遇到结束符\0就会停止。要无条件输出字符数组内的所有元素个数,那么只能遍历数组,逐个元素输出。
参考代码如下:
#include <iostream>