For a homework I was supposed to create a program in c++ (has to work in g++ to output some ascii art in a txt file. It works perfectly in Visual Studios, but when I compile g++ using cygwin I just get a single line.
Answers and Replies
Related Engineering and Comp Sci Homework Help News on Phys.org
What does one of the lines you're displaying look like?
My thought is that a newline character in VS isn't the same as what you need in cygwin. Windows and Unix/Linux work differently in this regard, with Windows using <CR> + <LF> (ASCII x0A and x0D) and Unix/Linux using just one of these characters.
I agree with the above poster that opening the file in WordPad will properly display the file. Probably you do not want to be restricted to WordPad. Alternatively you can use code like:
myfile << "\r\n" to force output. I prefer to use the standard coding: myfile << endl. I wish someone could tell me a way to include the right header, or make the proper settings somewhere to allow me to use the standard coding. In the meantime, you can try the following:
#define ENDL "\r\n"
myfile << ENDL;
The code then looks quite comparable to the standard C++ style, but with capitalization of ENDL throughout your program.
The different line endings between Unix and Windows. Cygwin emulates Unix, so it uses Unix line endings.
The lack of distinction between binary and text files in Unix. Cygwin by default opens output files in binary mode.
C++ I/O, which hides a lot of implementation details, including text versus binary mode.
Going back and forth between cygwin and Windows without using dos2unix/unix2dos.
Using Notepad which is singularly clueless about Unix line endings.
There is no problem if you use cygwin tools such as more, cat, and vi to example files produced by applications compiled with g++. There is no problem with regard to notepad and other Windows tools if you use minGW instead of g++. Don't use notepad and you won't have near so many problems. Use dos2unix and unix2dos and you also won't have near so many problems.
I recommend against using "\r\n". Do this and you'll have problems if you port your code to a Linux machine or to a Windows-aware compiler.