getline 和get的区别:
getline 每次读取一行,舍弃最后的换行符,下一个getline来的时候,直接读取下一行!
get每次读取一行,但是将每一行最后的换行符保留在输入队列中!下一个get来的时候,先读取输入队列中的换行符!
#include <iostream>
using namespace std;
int main()
{
const int Size=20;
char s1[Size];
char s2[Size];
cout<<"Enter the s1"<<endl;
cin.get(s1,Size);
cout<<"Enter the s2"<<endl;
cin.get(s2,Size);
cout<<"s1:"<<s1<<endl;
cout<<"s2:"<<s2<<endl;
return 0;
}
#include <iostream>
using namespace std;
int main()
{
const int Size=20;
char s1[Size];
char s2[Size];
cout<<"Enter the s1"<<endl;
cin.get(s1,Size);
cout<<"Enter the s2"<<endl;
cin.get(s2,Size);
cout<<"s1:"<<s1<<endl;
cout<<"s2:"<<s2<<endl;
return 0;
}