这个简单代码的问题 [英] problem with this simple code

查看:59
本文介绍了这个简单代码的问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

int main()
{
	students *s;
	int n=0;
	s=new students[n];
	char c='y';
	do
	{
		char *streams=new char[50];
		char *name=new char[50];
		int years,roll;
		cout<<"enter then stream";
		cin.get(streams,50);
		cout<<"enter the year of joining college";
		cin>>years;
		(s+n)->set_stream(streams,years);
		delete streams;
		cout<<"enter your name";
		cin.get(name,50);
		cout<<"enter the rollno";
		cin>>roll;
		(s+n)->set_data(name,roll);
		n++;
		cout<<endl<<endl<<"entry added";
		cout<<"do you want to add more entries";
		cin>>c;
		delete name;
	}while(c!='n');



i定义了班级学生,

当我运行此代码时,它要求输入流并输入年份

之后它不要求输入名称并停止运行


i have defined the class "students" ,
when i run this code, it asks for entering the stream and entering the year
after that it does not asks to enter name and stops running

推荐答案

有很多可能性为什么发生了这种情况。

不幸的是,我们无法分辨它中的哪一个,因为我们无法运行您的代码 - 我们不知道您的学生构造函数, set_stream 函数的作用。就此而言,问题可能在于你的数据 - 我们也不知道你输入了什么!



所以,这取决于你。幸运的是,你有一个可以在这里真正帮助的调试器 - 或者我假设你这样做,因为所有支持C ++的现代IDE都将拥有不同程度功能的调试器。如果您正在使用Visual Studio(我认为您是),那么调试器确实非常强大 - 但首先,您只需要基本功能。



开始通过在该行上设置一个断点:

There are quite a few possibilities as to why this happens.
And unfortunately we can't tell which one of the many it is, because we can't run your code - we have no idea what your students constructor does, of what the set_stream function does either. For that matter, it could be that the problem is with your data - we don't know what you typed either!

So, it's up to you. Fortunately you have a debugger which can really help here - or I assume you do, as all modern IDEs that support C++ will have a debugger of varying degree of power. If you are using Visual Studio (and I assume that you are) then the debugger is very powerful indeed - but to start with, you only need basic features.

Start by putting a breakpoint on the line:
(s+n)->set_stream(streams,years);

然后运行你的程序。当执行到达该行时,它将停止(在执行该行之前)并让您查看内存中的内容。跳过线(将有一个按钮,或标记为Step或Step over的菜单项 - 该功能是否完全返回?如果没有,则再次运行app,这次使用Step Into 开始执行函数本身。



通过重复此过程,查看变量,您应该能够缩小问题范围,并自行解决,或者至少给我们提供更好的信息来帮助你。

And run your program. When execution reaches the line, it will stop (before the line is executed) and let you look at what you have in memory. Step over the line (there will be a button, or menu item marked "Step" or "Step over" - does the function return at all? If it doesn't, then run you app again, and this time use "Step Into" to start executing the function itself.

By repeating this process, and looking at your variables, you should be able to narrow the problem down, and either solve it yourself, or at least give us better information with which to help you.


这篇关于这个简单代码的问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆