为什么当我调用告诉它的方法时,我的 deque 不会pop_front?
Why my deque won't pop_front when I call the method that tells it to?
所以,我有一个项目,我的一个类方法应该pop_front deque,mydeque。当我在 main 中调用 one.play() 并运行程序时,它不会弹出 deque。该程序应该让用户输入他们想要的卡数,然后在每次抽卡时生成一个随机数并比较卡上的值。如果随机数小于卡号,则分数递增 1。但是为了做到这一点,我需要弹出双面的正面,并将新数字与每次双面的新正面进行比较。
#include <iostream>
#include <deque>
using namespace std;
class Player {
private:
size_t cards;
deque<int> mydeque;
public:
string name;
int score;
Player(string player) {
name = player;
score = 0;
}
void recieve(size_t card){
mydeque.push_front (card);
}
int play() {
return mydeque.front();
mydeque.pop_front();
}
~Player() {
name = " ";
score = 0;
}
void tostring(ostream & out) const{
out << "player name : "<< name << endl;
out << "score : " << score << endl;
out << "cards : " << mydeque.size() << endl;
for(int i =0; i <mydeque.size();i++)
out << mydeque[i] << " " ;
}
};
ostream & operator <<(ostream & out, const Player & p){
p.tostring(out);
return out;}
int main () {
int rounds;
cout << "Give the number of rounds: "<<endl;
cin >> rounds;
Player one("some player");
for (int i = 1; i < rounds+1; i++){
one.recieve(i);
}
for( int i = 0; i < rounds; i++) {
one.play();
int randnum = rand()%(rounds-1 + 1) + 1;
cout << one << endl;
cout << " The dealer draws : " << randnum << endl;
if (randnum < one.play()){
one.score = one.score + 1;}}
return 0;
}
return
语句执行后,函数结束。
改变:
int play() {
return mydeque.front();
mydeque.pop_front();
}
自:
int play() {
int x = mydeque.front();
mydeque.pop_front();
return x;
}
相关文章:
- 我的神经网络不起作用 [XOR 问题]
- C++我的数学有什么问题,为什么我的代码不能正确循环
- 我的字符计数代码计算错误.为什么
- 为什么我的C#代码在调用回C++COM直到Task时会暂停.等待/线程.加入
- cmake在我的项目中所需的所有静态库都不成功
- 为什么我的代码在输出中增加了93天
- 我的简单if-else语句是如何无法访问的代码
- 为什么我的for循环不能正确获取argv
- 我的项目不会像"undefined reference to `grpc::g_core_codegen_interface'"那样使用未定义的引用错误进行编译
- 0-1背包代码中的错误.我的代码中有什么错误
- 当我的阵列太大时出现分段错误
- 如何确认我的constexpr表达式实际上已经在编译时执行
- 为什么二进制搜索在我的测试中不起作用
- 如何指定我希望我的LIB链接到的DLL文件?-Visual Studio 2019
- 我的代码中有错误吗?使用BGI图形的C++代码对我不起作用
- 当我在main中声明了我的2d数组时,为什么我的程序会退出
- 如何使用C++为我的容器 Deque 设置最大大小?
- 为什么当我调用告诉它的方法时,我的 deque 不会pop_front?
- 将STL Deque重新分配我的元素(C )
- 创建了一个 deque 类,但无法在我的二叉树类方法中声明