cin.get函数能用来从控制台读入字符

样例代码:

#include<bits/stdc++.h>
using namespace std;

int main()
{
    const int SIZE = 80;
    char buffer1[SIZE];
    cout<<"Enter a sentence:"<<endl;
    cin.get(buffer1, SIZE);
    cout<<buffer1<<endl;
}

cin.getline函数和get用法和功能相似,区别只在于,cin.getline()在行的末尾舍弃换行符,而get()会保留换行符。

转载请注明来源:https://www.longjin666.top/?p=915

欢迎关注我的公众号“灯珑”,让我们一起了解更多的事物~

你也可能喜欢

发表评论

您的电子邮箱地址不会被公开。 必填项已用*标注