"New line" not being recognised by a Portland comp

I have a largish piece of code that runs well, except when I compile it on a Portland compiler running on Linux. In that case the output I get is one long line of text after another. In place of where a new line should start there is a small rectangle.

For example, when I run this code on the Portland compiler running on Linux:


#include <iostream.h>
#include <fstream.h>

using namespace std;
ofstream wout;

char chrResultsFile[50];

int main()
    {
    strcpy(chrResultsFile, "Results.txt");
    wout.open (chrResultsFile, ofstream::out | ofstream::app);

    wout << endl << "NEW GAME" << endl << endl;
    wout << "The initial configuration has 10 rows and 10 columns." << endl;
    }



The output that I’m getting is this:

“NEW GAME The initial configuration has 10 rows and 10 columns.”

rather than this:

"NEW GAME

The initial configuration has 10 rows and 10 columns."

That is, apparently the hard return ‘endl’ is not being recognised as such.

I am running the code by typing “pgCC filename.cpp -mp” on the command line.

Any suggestions would be most welcome.

Hi Corsica,

It works for me. What version of the compiler and what version of Linux are you using?

% cat test.cpp
#include <iostream.h>
#include <fstream.h>

using namespace std;
ofstream wout;

char chrResultsFile[50];

int main()
    {
    strcpy(chrResultsFile, "Results.txt");
    wout.open (chrResultsFile, ofstream::out | ofstream::app);

    wout << endl << "NEW GAME" << endl << endl;
    wout << "The initial configuration has 10 rows and 10 columns." << endl;
    }


% pgCC test.cpp -mp -o test.out
% test.out
% cat Results.txt

NEW GAME

The initial configuration has 10 rows and 10 columns.
%
  • Mat

Thank you for your reply. I’ll find the information that you asked for and post it.

Thanks,
Corsica

Compiler:
Portland pgCC 7.0-2

Operating system:
Redhat Linux 9.0

Thank you for any further suggestions.
Corsica

Ho Corsica,

Still works for me. Can you please post your exact commands, simular to what I have below?

Thanks,
Mat

redhat90-32:/tmp% pgCC -V

pgCC 7.0-2 32-bit target on x86 Linux
Copyright 1989-2000, The Portland Group, Inc.  All Rights Reserved.
Copyright 2000-2007, STMicroelectronics, Inc.  All Rights Reserved.
redhat90-32:/tmp% pgCC test.cpp -o test.out
redhat90-32:/tmp% test.out
redhat90-32:/tmp% cat Results.txt

NEW GAME

The initial configuration has 10 rows and 10 columns.

Thanks for your reply.

I’ve realised that when I open the file using ‘cat results.txt’ the output is correct, i.e. if I do what you’ve been doing, the output is correct.

But when I open it by double clicking the file name in Windows there are small rectangles in place of the hard returns.

Unfortunately, for my work, both representations must be correct.

[cs4un2@node92 rtp]$ pgCC Test.cpp -mp
[cs4un2@node92 rtp]$ ./a.out
[cs4un2@node92 rtp]$ cat Results.txt

NEW GAMES

The initial configuration has 10 rows and 10 columns.

So, this is right in this representation, but when I open the file in Windows I find the problem…

Corsica

When I copy the contents of Results.txt and paste it into Windows, it is represented correctly.

I would still like to find a ‘proper solution’, so further suggestions would be most welcome.

Corsica

Oops, it is represented correctly when I paste it into WORD, not Windows.

Hi Corsica,

Newlines are different in Windows and Linux and your text file will need to be converted before transferring from one system to another. Try running ‘unix2dos Results.txt’ before coping it Windows, or ‘dos2unix’ when going from Windows to Linux.

See: http://en.wikipedia.org/wiki/Newline for a full explanation.

  • Mat

Thank you for your brief and helpful reply, which resulted in a solution.

I’d actually done quite a lot of related searching and reading before posting the question to this forum, but it was your recent reply, which I read today, that resulted in my finding a solution.

Now, I’ll push on with this work and take more steps in my first encounter with Linux.

Thank you very much for your help in this.

Corsica