[英]How to print the contents of a Queue
I can't figure out what I am doing wrong here. 我无法弄清楚我在做什么错。 I am trying to print out my entire queue (which holds weather history) and it won't work. 我正在尝试打印出我的整个队列(其中保存了天气历史记录),它将无法正常工作。 When I try and debug it, it shows me that it is holding the values in the queue correctly, but not assigning it correctly. 当我尝试对其进行调试时,它表明它正确地将值保存在队列中,但未正确分配它。 How can i output the contents of my queue correctly? 如何正确输出队列中的内容? Here is my code: 这是我的代码:
Temp.cpp 温度cpp
ostream &operator<<( ostream &out, Temperature &p)//Overloaded Method to output the data
{
fstream myEngFile5;
string tempLine5;
string tempLine6;
myEngFile5.open("English.txt");
myEngFile5.seekg(335);
getline(myEngFile5, tempLine5);
out<<tempLine5<<p.value; //The Temperature is __
myEngFile5.seekg(356);
getline(myEngFile5, tempLine6);
out<<tempLine6<<"\n"; //F
return out;
}
Temp.h 温度h
int getTemp();
int getTemp2();
Temperature()
{
value=0;
}
Temperature(int v)
{
value=v;
}
friend ostream &operator<<(ostream &out,Temperature &p);
Source.cpp Source.cpp
queue<int>temp;//decalred in the begining
.
.
.
for(int i=0; i<temp.size(); i++){
int qSize=temp.size();
Temperature p2(temp.front());
while( !temp.empty()){
cout<<p2;
temp.pop();}
}
Is this what you are looking for (untested)?: 这是您要寻找的(未经测试的)吗?:
while (!temp.empty()) {
Temperature p2(temp.front());
cout << p2;
temp.pop();
}
It seems like you might be better off using queue<Temperature> and constructing your Temperature objects when you fill your queue. 似乎您最好在使用queue <Temperature>并在填充队列时构造温度对象。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.