我想用C ++转换这段代码 [英] I want to convert this code in C++
本文介绍了我想用C ++转换这段代码的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我想用c ++转换这段代码
i want to convert this code in c++
void makeMove(int *x, int *y)
{
// Take the input move
printf("Enter your move, (row, column) -> ");
scanf("%d %d", x, y);
return;
}
我的尝试:
What I have tried:
void makeMove(int *x, int *y)
{
// Take the input move
cout << "Enter your move, (row, column) -> ";
cin >>x >>y;
return;
}
推荐答案
我认为它没有优势,但是你去了:
这应该有效:
I see no advantage in it, but here you go:
This should work:
cin >> *x >> *y;//de ref the pointers
最好使用说出名字,并指出一个前缀p
It is better to work with "speaking names" and give pointers a prefix "p"
void makeMove(int *px, int *py)
在更复杂的场景中你会理解的更好。
In more complex scenarios you will understand that better.
使用C ++
你可以使用引用:
WithC++
you might use references:
void makeMove(int & x, int & y)
{
// Take the input move
cout << "Enter your move, (row, column) -> ";
cin >> x >> y;
}
这篇关于我想用C ++转换这段代码的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文