cin.getline&cin.ignore
#include<iostream>
using namespace std;
int main()
{
char buf[20];
cin.ignore(5);
cin.getline(buf,10);//相当只有9个,最后要'\0'
cout<<buf<<endl;
}
?cin.peek&cin.get
#include<iostream>
using namespace std;
int main()
{
char p;
cout<<"请输入一段文本:\n";
while(cin.peek()!='\n')
{
p=cin.get();
cout<<p;
}
cout<<endl;
}
cin.read&cin.gcoun
#include<iostream>
using namespace std;
int main()
{
const int size = 50;
char buf[size];
cout<<"请输入一段文本:\n";
cin.read(buf,20);
cout<<"字符串收集到的字符数为:"
<<cin.gcount()<<endl;
cout<<"输入的文本信息是:";
cout.write(buf,20);
cout<<endl;
}