C++ 输入输出,IO

1.printf()从右到左计算输出.
int i = 3;
printf("%d %d", ++i, ++i);
结果:5 5
2.fputc()

函数名称:写字符文件函数fputc()
函数格式:int fputc (char c, File *fp)
参数解释:fp为 文件指针,它的值是执行fopen()打开文件时获得的。

程序例一

#include <stdio.h>
#include <string.h>
int main(void)
{
char msg[]="Hello world";
int i=0;
while(msg[i]&&(i<strlen(msg)))
{
fputc(msg[i],stdout);//输出到控制台
i++;
}
return0;
}

程序例二

#include <stdio.h>
#include <stdlib.h>
void main()
{
FILE*fpout;
char ch;
if((fpout=fopen("file_a.dat","w"))==NULL)
{
printf("Error!\n");
exit;
}
ch=getchar();
for(;ch!='#';)
{
fputc(ch,fpout);
ch=getchar();//不能仅写getchar();
}
fclose(fpout);
}

程序例三

#include <stdio.h>
#include <string.h>
int main()
{
FILE*f;
char*s="Hey,Buddy!";
int i;
f=fopen("myFile.txt","w");
for(i=0;i<strlen(s);i++)
fputc(s[i],f);
fclose(f);
return0;
}

 



转载于:https://www.cnblogs.com/wuyuntao/p/5312662.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值