网页资讯视频图片知道文库贴吧地图采购
进入贴吧全吧搜索

 
 
 
日一二三四五六
       
       
       
       
       
       

签到排名:今日本吧第个签到,

本吧因你更精彩,明天继续来努力!

本吧签到人数:0

一键签到
成为超级会员,使用一键签到
一键签到
本月漏签0次!
0
成为超级会员,赠送8张补签卡
如何使用?
点击日历上漏签日期,即可进行补签。
连续签到:天  累计签到:天
0
超级会员单次开通12个月以上,赠送连续签到卡3张
使用连续签到卡
08月27日漏签0天
c++吧 关注:630,543贴子:2,113,824
  • 看贴

  • 图片

  • 吧主推荐

  • 游戏

  • 0回复贴,共1页
<<返回c++吧
>0< 加载中...

cin的问题!

  • 只看楼主
  • 收藏

  • 回复
  • Rulss
  • ,
    1
该楼层疑似违规已被系统折叠 隐藏此楼查看此楼
代码如下:
#include <stdio.h>
#include <stdlib.h>
#include <iostream>
#include <string.h>
using namespace std;
static int m=0,i=0;
void create(int **v);
void input(int *v);
void insert(int *v);
void del(int *v);
void print(int *v);
void menue();
void main()
{
int *v;
int ch;
menue();
while(1)
{
scanf_s("%d",&ch);
switch (ch)
{
case 1:
create(&v);
break;
case 2:
input(v);
print(v);
break;
case 3:
insert(v);
print(v);
break;
case 4:
del(v);
print(v);
break;
case 5:
print(v);
break;
case 6:
exit(0);
}
}
}
void create(int **v)
{
int *p;
printf("Input the length:");
cin>>m;
p=(int *)malloc(sizeof(int)*m);
*v=p;
}
void input(int *v)
{
i=0;
char s[5],de[]="end";
cout<<"Input number(press \"end\" to end):"<<endl;
while(1)
{
if(i==m)
{
cout<<"Full!you can't input any number then!"<<endl;
break;
}
scanf_s("%d",v+i);
gets_s(s);
if(strcmp(s,de)==0)
break;
i++;
};
}
void insert(int *v)
{
int q,j,s;
if(i==m)
{
cout<<"The form is full!can't insert!\n";
return;
}
cout<<"Input a number you want to insert:";
cin>>q;
cout<<"Input a location you want to insert:";
cin>>j;
for(s=i-1;s>=j-1;s--)
{
*(v+s+1)=*(v+s);
}
*(v+j-1)=q;
i++;
return ;
}
void del(int *v)
{
int q,s;
if(m==0)
{
printf("The form is empty!can't delete!\n");
return;
}
cout<<"Input the location of number you want to delete:";
cin>>q;
for(s=q-1;s<=i-1;s++)
{
*(v+s)=*(v+s+1);
}
i--;
}
void print(int *v)
{
int q;
cout<<"After operation:"<<endl;
for(q=0;q<=i-1;q++)
cout<<*(v+q)<<endl;
}
void menue()
{
printf("Press 1 to create a form!\n");
printf("Press 2 to add number to the form!\n");
printf("Press 3 to insert a number!\n");
printf("Press 4 to delete a number!\n");
printf("Press 5 to print the form!\n");
printf("Press 6 to exit!\n");
}
函数input中,用scanf_s()可以正常运行,而用cin>>*(v+i);后可以输入但是执行到insert函数会报错,这是为啥呢?


登录百度账号

扫二维码下载贴吧客户端

下载贴吧APP
看高清直播、视频!
  • 贴吧页面意见反馈
  • 违规贴吧举报反馈通道
  • 贴吧违规信息处理公示
  • 0回复贴,共1页
<<返回c++吧
分享到:
©2025 Baidu贴吧协议|隐私政策|吧主制度|意见反馈|网络谣言警示