#include <iostream>
using namespace std;
int main( )
{
char c;
while(!cin.eof( )) //eof( )为假表示未遇到文件结束符
if((c=cin.get( ))!=' ') //检查读入的字符是否为空格字符
cout.put(c);
return 0;
}
C++ is very interesting.↙ C++isveryinteresting. ^Z(结束)
c=cin.peek( );
cin.putback(ch);
#include <iostream>
using namespace std;
int main( )
{
char c[20];
int ch;
cout<<"please enter a sentence:"<<endl;
cin.getline(c,15,'/');
cout<<"The first part is:"<<c<<endl;
ch=cin.peek( ); //观看当前字符
cout<<"The next character(ASCII code) is:"<<ch<<endl;
cin.putback(c[0]); //将'I'插入到指针所指处
cin.getline(c,15,'/');
cout<<"The second part is:"<<c<<endl;
return 0;
}
please enter a sentence: I am a boy./ am a student./↙ The first part is:I am a boy. The next character(ASCII code) is:32(下一个字符是空格) The second part is:I am a student
cin.ignore(n, 终止字符)
ighore(5, 'A') //跳过输入流中个字符,遇'A'后就不再跳了
ignore( ) // n默认值为,终止字符默认为EOF
ignore(1, EOF)
#include <iostream>
using namespace std;
int main( )
{
char ch[20];
cin.get(ch,20,'/');
cout<<"The first part is:"<<ch<<endl;
cin.get(ch,20,'/');
cout<<"The second part is:"<<ch<<endl;
return 0;
}
I like C++./I study C++./I am happy.↙ The first part is:I like C++. The second part is:(字符数组ch中没有从输入流中读取有效字符)
#include <iostream>
using namespace std;
int main( )
{
char ch[20];
cin.get(ch,20,'/');
cout<<"The first part is:"<<ch<<endl;
cin.ignore( );//跳过输入流中一个字符
cin.get(ch,20,'/');
cout<<"The second part is:"<<ch<<endl;
return 0;
}
I like C++./I study C++./I am happy.↙ The first part is:I like C++. The second part is:I study C++.
机械节能产品生产企业官网模板...
大气智能家居家具装修装饰类企业通用网站模板...
礼品公司网站模板
宽屏简约大气婚纱摄影影楼模板...
蓝白WAP手机综合医院类整站源码(独立后台)...苏ICP备2024110244号-2 苏公网安备32050702011978号 增值电信业务经营许可证编号:苏B2-20251499 | Copyright 2018 - 2025 源码网商城 (www.ymwmall.com) 版权所有