C++中的字符串输入getline
2024-10-19 15:30:38
http://www.cnblogs.com/wanghao111/archive/2009/09/05/1560822.html
1 #include <iostream>
2 #include <string>
3 using namespace std;
4
5
6 /* run this program using the console pauser or add your own getch, system("pause") or input loop */
7
8 int main(int argc, char** argv) {
9
10 string s;
11 char p[10];
12 char q[10];
13
14 //cin.getline(p,4);//最大只能接受3个字符,自动在末尾加上'\0'
15 cout<<"p="<<p<<endl;
16
17 cin.getline(q,3,'\0');//输入字符串以'\0' 结尾 ,大只能接受3个字符
18 cout<<"q="<<q<<endl;
19
20
21
22 getline(cin,s);
23 cout<<"s"<<s<<endl;
24
25 cout<<"p="<<p<<endl;
26 cout<<"q="<<q<<endl;
27 cout<<"s"<<s<<endl;
28 return 0;
29 }
最新文章
- Base64原理
- 学习 Local Sensitive Hash
- Web服务器之iis,apache,tomcat三者之间的比较
- NHibernate系列文章九:NHibernate对象二级缓存上
- 继续努力刷题--BE STRONGER AND STRONGER
- iOS-代理
- 一个简单的脚本让你的ubuntu14.04记忆屏幕亮度
- 用JS查看修改CSS样式(cssText,attribute(&#39;style&#39;),currentStyle,getComputedStyle)
- NUnit使用详解(一)
- jQuery动态效果实例
- 移动端Web开发如何处理横竖屏
- centos7 开机启动某些程序的方法
- swift2.0 UIImagePickerController 拍照 相册 录像
- 避免ssh断开导致运行命令的终止:screen
- Java NIO 学习总结 学习手册
- RobotFrame连接MySql数据库
- C++ 函数模板“偏特化”
- 设计模式のDecoratorPattern(装饰器模式)----结构模式
- JavaScript基础笔记(十)表单脚本
- lvs笔记