我有问题eror struct指针C ++ [英] I have problem eror struct pointer C++
本文介绍了我有问题eror struct指针C ++的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
指针有问题..
所以当我输入时:
2 3,
2 5,
2 7,
2 9,
2 11,
1 1
输出:
Nilai; 3,
next = 4;
为什么testt.next是4 ??
i想要testt.next = 5;
我的尝试:
i have problem with pointer..
so when i input:
2 3,
2 5,
2 7,
2 9,
2 11,
1 1
Output :
Nilai ; 3,
next = 4;
why testt.next is 4 ??
i want testt.next = 5;
What I have tried:
<pre>#include <iostream>
using namespace std;
struct test
{
int next;
int previous;
int nilai = 0;
};
int main()
{
test *coba, testt;
coba = &testt;
int z;
string perintah;
int y = 0;
while(true)
{
cout << "Input : ";
cin >> perintah;
if(perintah == "2")
{
if(testt.nilai != 0){
*(++coba);
}
cin >> (*coba).nilai;
y++;
}
if(perintah == "1")
{
cin >> z;
for(int i = 0; i < y-z; i++)
{
*(--coba);
}
cout << "Nilai ; " << (*coba).nilai << endl;
cout << "next / previous ? : ";
cin >> perintah;
if(perintah == "next")
{
*(++coba);
testt.next = (*coba).nilai;
cout << testt.next;
for(int i = 1; i < y-z; i++)
{
*(++coba);
}
}
}
}
return 0;
}
推荐答案
请看这里:如何删除C ++中的地址指针 [ ^ ]
这篇关于我有问题eror struct指针C ++的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文