Weird glitch/bug with c++ program compiled in Ubuntu? or am I doing something wrong?

John Shaver bobjohnbob at gmail.com
Wed Feb 15 14:51:44 MST 2012


I'm taking a basic C++ class for school and while it's normally pretty
easy, I got stumped by a weird problem last night.

The assignment was to write a program to convert infix expressions to
postfix expressions.  I write all my homework assignments in Ubuntu
and then cross compile them for windows since we're required to turn
in a windows executable.

Everything was all ready except that my output was missing spacing so
all the numbers would run together.

Like this:

853+*
instead of this:

8 5 3 + *

So I added "<< ' ';" at the end of each cout statement that printed an
operand or operator.

Suddenly, in my program output, the first operand of each converted
postfix statement was replaces with a space and I can't figure out
why.   The weird thing though... The windows executable work just
fine??

Here is a link where you can download the source code.  If you want to
compile it with the makefile, you'll need g++ and mingw installed.
Otherwise plug the two cpp files into your own compiler.  There is a
windows executable and a binary file compiled under Ubuntu 11.10 in
there as well.

Compare the output below.

Correct output from $wine ./project5.exe:

4
5 7 +
7 5 *
5 3 -
5 5 /
8 5 * 3 +

Broken output from $./project05

  7 +
  5 *
  3 -
  5 /
  5 * 3 +

I can't figure out what would cause this.  As you can see in the
source, I tried flushing cout after each cout statement to make sure
it wasn't getting changed somehow before it was flushed from the
buffer, but it had no effect.  I was able to turn my assignment in
fine, since it didn't require anything but the source and the windows
executable, but it's driving me cray not knowing what is causing this.

Any ideas?

-John Shaver


More information about the PLUG mailing list