我试图插入并显示类类型数组中的值可以有人让我说对了吗?谢谢 [英] I tried to insert and display values from class type array can somebody make me right ? thank you

查看:62
本文介绍了我试图插入并显示类类型数组中的值可以有人让我说对了吗?谢谢的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

#include<iostream>
using namespace std;
Class one
{
	public:
	string first;
	string second;
	int previousValue;
	int nextValue;
	void getData();
	void setData();
};
class two
{
	public:
	one array[10];
	void loadRecord();
};
int main()
{
	two ins;
	return 0;
}
two::loadRecord()
{
	for(int i=0;i<10;i++)
	{
		array[i]=//doesnot take input
	}
	for(int i=0;i<10;i++)
	{
		cout<<array[i]<<endl;//doesnot give output
	}

}





我尝试了什么:



上面的代码我试过但它没有给出输出



What I have tried:

the code above i have tried but it didnt give the output

推荐答案

在这一行:

At this line:
two ins;



..你创建一个实例 ins 你的班级两个。这就是你的程序在它终止之前所做的全部。



你需要在它上面实际调用 loadRecord()



在这一行:


..you create an instance "ins" of your class two. And that's all your program does before it terminates.

You need to actually call loadRecord() on it.

And on this line:

array[i]=



..看起来你想要为你的班级分配一个新实例一个单个数组索引,但已经有(未初始化的)实例。



还有更多问题,但我建议你先解决这些问题。



我建议你为你的班级,班级成员和实际意味着什么的地方变量使用名称。一旦你的程序变得更大,one,two,ins,array就会变得非常混乱。


..it looks like you want to assign a new instance of your class one to the individual array indices but there already are (uninitialized) instances.

There are more issues but I suggest you start with fixing these.

I would recommend you to use names for your classes, class members and local variables that actually mean something. "one", "two", "ins", "array" will get pretty confusing once your programs get a bit larger.


你应该学会尽快使用调试器。而不是猜测你的代码在做什么,现在是时候看到你的代码执行并确保它完成你期望的。



调试器允许你跟踪执行逐行检查变量,你会看到有一点它会停止你所期望的。

在Visual Studio 2010中掌握调试 - 初学者指南 [ ^ ]

http://docs.oracle.com/javase/7/docs/technotes/tools/windows/jdb.html [ ^ ]

https://www.jetbrains.com/idea/help/debugging-your-first-java-application.html [ ^ ]
You should learn to use the debugger as soon as possible. Rather than guessing what your code is doing, It is time to see your code executing and ensuring that it does what you expect.

The debugger allow you to follow the execution line by line, inspect variables and you will see that there is a point where it stop doing what you expect.
Mastering Debugging in Visual Studio 2010 - A Beginner's Guide[^]
http://docs.oracle.com/javase/7/docs/technotes/tools/windows/jdb.html[^]
https://www.jetbrains.com/idea/help/debugging-your-first-java-application.html[^]


这篇关于我试图插入并显示类类型数组中的值可以有人让我说对了吗?谢谢的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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