c++获取键盘输入cin、scanf使用详解
2017-09-01 11:30
519 查看
cin是c++标准,scanf是在c中使用的
#include<cstdio> #include<iostream> #include<cstring> using namespace std; int main() { /* strlen包含在string.h头文件里,加上 #include <string.h> #include <cstring> // C语言头文件为 string.h 新c++编译器 ,前面加c ,后去掉 .h 输入char[] */ char s[100100]; cin>>s; //strlen和sizeof的区别 int len = strlen(s); int size = sizeof(s); //100100 cout<<s<<" "<<len<<" "<<size<<endl; //连续输入多个变量 double z,g; int h; cin>>z>>g>>h; cout<<z<<" "<<g<<" "<<h<<endl; //输入string string str; cin>>str; int len1 = str.length(); int size1 = str.size(); cout<<str<<" "<<len1<<" "<<size1<<endl; /* printf,scanf两个函数都包含在库文件<stdio.h>中。 连续输入多个变量 */ double x,y; int w; scanf("%lf%lf%d",&x,&y,&w); printf("%lf %lf %d",x,y,w); return 0; }
纯文本代码:
#include<cstdio> #include<iostream> #include<cstring> using namespace std; int main() { /* strlen包含在string.h头文件里,加上 #include <string.h> #include <cstring> // C语言头文件为 string.h 新c++编译器 ,前面加c ,后去掉 .h 输入char[] */ char s[100100]; cin>>s; //strlen和sizeof的区别 int len = strlen(s); int size = sizeof(s); //100100 cout<<s<<" "<<len<<" "<<size<<endl; //连续输入多个变量 double z,g; int h; cin>>z>>g>>h; cout<<z<<" "<<g<<" "<<h<<endl; //输入string string str; cin>>str; int len1 = str.length(); int size1 = str.size(); cout<<str<<" "<<len1<<" "<<size1<<endl; /* printf,scanf两个函数都包含在库文件<stdio.h>中。 连续输入多个变量 */ double x,y; int w; scanf("%lf%lf%d",&x,&y,&w); printf("%lf %lf %d",x,y,w); return 0; }
纯文本代码:
#include<cstdio> #include<iostream> #include<cstring> using namespace std; int main() { /* strlen包含在string.h头文件里,加上 #include <string.h> #include <cstring> // C语言头文件为 string.h 新c++编译器 ,前面加c ,后去掉 .h 输入char[] */ char s[100100]; cin>>s; //strlen和sizeof的区别 int len = strlen(s); int size = sizeof(s); //100100 cout<<s<<" "<<len<<" "<<size<<endl; //连续输入多个变量 double z,g; int h; cin>>z>>g>>h; cout<<z<<" "<<g<<" "<<h<<endl; //输入string string str; cin>>str; int len1 = str.length(); int size1 = str.size(); cout<<str<<" "<<len1<<" "<<size1<<endl; /* printf,scanf两个函数都包含在库文件<stdio.h>中。 连续输入多个变量 */ double x,y; int w; scanf("%lf%lf%d",&x,&y,&w); printf("%lf %lf %d",x,y,w); return 0; }
相关文章推荐
- c++获取键盘输入cin、scanf使用详解
- C++输入cin详解
- (VS2012)C++行输入函数的使用(scanf_s,cin.getline,cin.get)
- C++ 标准输入 cin 使用
- C++输入cin详解
- C++ 输入cin详解
- C++ 读取键盘输入(cin/cin.getline()/cin.get()/cin.clear())
- C++输入cin详解
- 使用BufferedReader获取键盘输入
- C++输入cin详解
- C++输入cin详解
- 使用cin获取用户的输入信息
- C++输入cin详解
- C++输入cin详解
- 【C++ Primer】C++输入cin详解
- while ((ch = getchar()) != EOF)中ch定义为char还是int型?cin、scanf等如何结束键盘输入
- C++输入cin详解
- C++输入cin详解
- 使用BufferedReader获取键盘输入
- Linux C编程 使用scanf时清除键盘缓冲区 -- 清除输入缓存