
这2个没有什么联系,int是数据类型,表示整型,而cin代表标准输入设备,使用提取运算符 ">>" 从设备键盘取得数据,送到输入流对象cin中,然后送到内存。使用cin可以获得多个从键盘的输入值,基础知识你要好好学哦
声明了 char ch; 一个字符。
cin >>ch; 每次 只从输入流中读取一个字符
for(i = 7;i >= 0; i--) 循环 8 次 读取 8个字符
无论输入 00010001 或输入0 0 0 1 0 0 0 1 结果一样。cin只是到输入缓冲区取数。默认空白为分隔符,(有空白就跳过,没空白只读一个字符)。
输入一次 00010001 ,缓冲区就有了00010001, cin >>ch; 每次只用掉一个字符。
用gets(str);
#include<stdioh>
#include<iostreamh>
#include<conioh>
void fun(char s[], char c)
{
char ch=NULL;
int i=0;
ch=s;
while(ch)
{
if(ch!=c)
{
s[i]=ch;
i++;
}
ch++;
}
s[i]='\0';
}
void main()
{
static char str[100];
char ch;
cout<<"原始字符串:"<<endl;
gets(str);
cout<<"输入一个字符:";
cin>>ch;
fun(str,ch);
cout<<"str="<<str<<endl;
}
程序出错了 改了好多 你自己对着看吧
主要问题是插入元素时指针指得不好
#include<iostream>
using namespace std;
#include<stringh>
#include<malloch>
typedef char Name;
typedef int Num;
typedef float Score;
typedef struct LNode
{
Name data1[10];
Num data2;
Score data3,data4;
struct LNode next;
}LinkList;
void ListInsert(LinkList &L,Num i,Name a[],Num b,Score c,Score d);
void LocateElem(LinkList L,Num a);
int main()
{
LinkList h,p,s;
h=(LinkList )malloc(sizeof(LinkList));
p=h;
p->next=NULL;
cout<<"the number of students"<<endl;
Num n,i;
Name a[10];
Num b;
Score c,d;
cin>>n;
for(i=0;i<n;i++)
{
s=(LinkList )malloc(sizeof(LinkList));
cout<<"please input the message of the"<<i+1<<"student!"<<endl;
cout<<"num"<<" "<<"name"<<" "<<"score1"<<" "<<"scor2"<<endl;
cin>>b>>a>>c>>d;
strcpy(s->data1,a);
s->data2=b;
s->data3=c;
s->data4=d;
s->next=p->next;
p->next=s;
}
cout<<"please input the message of the one want to insert!\nlocation,name,number,score1,score2"<<endl;
Name m[10];
Num z,g;
Score y,o;
cin>>g>>m>>z>>y>>o;
ListInsert(p,g,m,z,y,o);
cout<<"please input the school number you want to search!";
int k;
cin>>k;
LocateElem(p,k);
return 0;
}
void ListInsert(LinkList &L,Num i,Name a[],Num b,Score c,Score d)
{
Num j=0;
LinkList p=L,s;
while(j<i-1&&p!=NULL)
{
j++;
p=p->next;
}
if(p==NULL)
cout<<"can not find the location!"<<endl;
else
{
s=(LinkList )malloc(sizeof(LinkList));
strcpy(s->data1,a);
s->data2=b;
s->data3=c;
s->data4=d;
s->next=p->next;
p->next=s;
cout<<"insert successfully!"<<endl;
}
}
void LocateElem(LinkList L,Num a)
{
LinkList p=L->next;
Num n=1;
while(p!=NULL&&p->data2!=a)
{
p=p->next;
n++;
}
if(p==NULL)
cout<<"the one want to know is not exsit!"<<endl;
else
{
cout<<"the student is locate on "<<n<<endl;
}
}
ps:你的程序风格不好 最好多加点注释 并且注意代码缩进和空格
当你在控制台输完数据敲回车后,输入的数据以及回车换行符被同时送到输入缓冲区,例如你输入的数据为a,然后回车,此时输入缓冲区中就有两个字符,一个是‘a’,一个是回车换行符‘/n’,接着程序读取,由于类型不匹配,读取失败,并没有读走输入缓冲区中的数据,也就是说,此时输入缓冲区中还是‘a’,和‘\n’,接着while循环继续读输入缓冲区,依然类型不匹配,于是就成了死循环
cin代表标准输入设备,使用提取运算符
">>"
从设备键盘取得数据,送到输入流对象cin中,然后送到内存。使用cin可以获得多个从键盘的输入值
cout
编程语言互换流中的标准输出流,需要iostreamh支持。读为
"c
out"。
char是定义字符变量
define
宏的格式“#define
标识符
字符串”
int
定义整型变量
break
是用在switch语句里,可使程序跳出switch而执行switch以后的语句
以上就是关于C语言中int与cin的区别是什么全部的内容,包括:C语言中int与cin的区别是什么、一个简单的c++程序,里面的cin是怎么接收的输入数据的、在这个程序中怎么用cin输入空格等相关内容解答,如果想了解更多相关内容,可以关注我们,你们的支持是我们更新的动力!
欢迎分享,转载请注明来源:内存溢出
微信扫一扫
支付宝扫一扫
评论列表(0条)