How can I get rid of that junk printed in front of the output

1
2
3
4
5
6
34 12 64 56 28 91 21 11 82 -999
Contents of q1:1990782048  34  12  64  56  28  91  21  11  82
Contents of q2:1990782048  34  12  64  56  28  91  21  11  82
Process returned 0 (0x0)   execution time : 48.472 s
Press any key to continue.

here is the code:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
 #include <iostream>
#include <queue>
#include <list>
using namespace std;

int main(void) {
    queue<int> q1;
    queue<int> q2;
   int i;
   while(i!= -999)
   {
       q1.push(i);
       cin >>i;
   }
    q2 = q1;

   cout << "Contents of q1:" ;
   while (!q1.empty()) {
      cout << q1.front() << "  ";
      q1.pop();
   }

   cout << endl;

   cout << "Contents of q2:" ;
   while (!q2.empty()) {
      cout << q2.front() << "  ";
      q2.pop();
   }

   return 0;
}
1
2
3
4
   int i;             // i doesn't yet have a value
   while(i!= -999)    // i could have any value at this point; let's guess it's not -999
   {
       q1.push(i);    // we haven't given i a value ... but let's put it in the queue anyway 



How about:
1
2
3
4
5
6
7
   int i;
   while( true )
   {
       cin >>i;
       if ( i == -999 ) break;
       q1.push(i);
   }
Last edited on
Thank you very much lastchance!!!!
Input could fail (those **** users ...). Therefore:
1
2
3
4
5
int i {};
while( cin >> i and i != -999 )
{
  q1.push( i );
}
Or you could keep it really short and sweet:
for (int i; cin >> i && i!= -999; ) q1.push(i);
@lastchance, it should be || instead of &&.
Are you sure?
I was for about 2 seconds.
WTF was I thinking???
Topic archived. No new replies allowed.