除了使用预定义的插入符进行屏幕输出,cout<<“ ”
还可以使用write函数:
显示器输出一个字符串函数,使用格式如下
cout.write(const char * str, int n)
其中,str是一个用来存放字符串的字符指针或字符数组名,也可以 用一个字符串常量。 n指定输出的字符个数。
s="hello, world!"
cout.write(s,strlen(s)).put('\n');
cout.write(s,5)<<'\n';
输出的结果分别如下:
hello, world!
hello
注:cout.put(char c) 用于输出一个字符。
strlen(s)表示输出整个字符串s.