首页 > 代码库 > C++中cin流的简单使用
C++中cin流的简单使用
cin流可以用于读取标准输入流的一个字符,一行字符包含空格,多行字符等,示例如下:
#include <iostream>using std::cout;using std::endl;using std::cin;int main(void){ const int maxlength=100; char text[maxlength]={0}; char test=0; //读取一行文本,可以包含空格,以回车('\n')结束 cin.getline(text,maxlength); cout << "You entered:" <<endl<<text<<endl; //用'!'代替'\n',表示字符串的结束,这样就可以读取多行文本了 cin.getline(text,maxlength,'!'); cout << "You entered:" <<endl<<text<<endl; //读取单个字符 cin >> test; cout << "You entered:" << endl << test << endl; return 0; }
声明:以上内容来自用户投稿及互联网公开渠道收集整理发布,本网站不拥有所有权,未作人工编辑处理,也不承担相关法律责任,若内容有误或涉及侵权可进行投诉: 投诉/举报 工作人员会在5个工作日内联系你,一经查实,本站将立刻删除涉嫌侵权内容。