加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 百科 > 正文

c++获取键盘输入cin、scanf使用详解

发布时间:2020-12-16 09:09:04 所属栏目:百科 来源:网络整理
导读:cin是c++标准,scanf是在c中使用的 ? ? 1 #includecstdio 2 #includeiostream 3 #includecstring 4 5 using namespace std; 6 7 int main() 8 { 9 /* 10 strlen包含在string.h头文件里,加上 11 #include string.h 12 #include cstring // C语言头文件为 str

cin是c++标准,scanf是在c中使用的

?

?

 1 #include<cstdio>
 2 #include<iostream>
 3 #include<cstring>
 4 
 5 using namespace std;
 6 
 7 int main()
 8 {
 9     /*
10     strlen包含在string.h头文件里,加上
11     #include <string.h>
12     #include <cstring> // C语言头文件为 string.h 新c++编译器 ,前面加c ,后去掉 .h
13     输入char[]
14         */
15     char s[100100];
16     cin>>s;
17     //strlen和sizeof的区别
18     int len = strlen(s);
19     int size = sizeof(s); 100100
20     cout<<s<<" "<<len<<"<<size<<endl;
21 
22     连续输入多个变量
23     double z,g;
24      h;
25     cin>>z>>g>>h;
26     cout<<z<<"<<g<<"<<h<<27 
28     输入string
29     string str;
30     cin>>str;
31     int len1 = str.length();
32     int size1 = str.size();
33     cout<<str<<"<<len1<<"<<size1<<34 
35     36     printf,scanf两个函数都包含在库文件<stdio.h>中。
37     连续输入多个变量
38     39      x,y;
40      w;
41     scanf("%lf%lf%d",&x,&y,&w);
42     printf(%lf %lf %d",x,y,w);
43     return 0;
44 }

?

?

纯文本代码

#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;
//strlensizeof的区别
int len = strlen(s);
int size = sizeof(s); //100100
cout<<s<<" "<<len<<" "<<size<<endl;

//连续输入多个变量
两个函数都包含在库文件<stdio.h>中。
连续输入多个变量 */
double x,y;
int w;
scanf("%lf%lf%d",&w);
printf("%lf %lf %d",w);
return 0;
}

?

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读