Programming uder Cygwin

All questions regarding Windows programming, post here. API,COM, ActiveX, DirectX, OpenGL, MFC and so on...

Moderators: Darobat, RecursiveS, Dante Shamest, Bugdude, Wizard

Programming uder Cygwin

Postby ramansingh » Sat Jun 28, 2008 4:27 am

Hi all,
I wrote a program to read binary floating point data from std::cin.
Code: Select all
float val;
std::cin.read( (char*) &val, sizeof(float) );
std::cerr << "Value= " << val << std::endl;


Then I compiled it under cygwin using
> g++ prog.cc

Then I executed it using
> ./a.exe < data.rsf
where data.rsf contains an ascii header followed by thousands of floating point data values written in binary.
So, far things were fine and the resulting exe file works perfect.

Then I wanted to have a native windows executable and therefore compiled the same code without using cygwin libraries using
> g++ -mno-cygwin prog.cc

This time, the resulting exe reads a few data values and then terminates as it unexpectedly finds EOF.

Can anybody explain why this native windows executable fails to read binary data from std::cin. Does my mingw need extra libraries?

Thanks in advance,
Raman
ramansingh
 
Posts: 1
Joined: Sat Jun 28, 2008 4:06 am

Postby devil_slayer » Thu Jul 03, 2008 4:03 pm

In windows (unlike linux) it is always important to differentiate between binary and ascii file formats. To do what you mentioned above I'd use sth like this:
float val;
std::ifstream file("data.rsf",std::ios::binary);
file.read((char*)&val,sizeof(float));
User avatar
devil_slayer
 
Posts: 489
Joined: Wed Oct 01, 2003 3:44 am
Location: Warsaw, POLAND


Return to Windows Programming

Who is online

Users browsing this forum: No registered users and 2 guests