Click here to Skip to main content
15,911,789 members
Home / Discussions / C / C++ / MFC
   

C / C++ / MFC

 
GeneralSliderBar Control Pin
shijuck23-May-05 22:46
shijuck23-May-05 22:46 
QuestionHow to read the floppy sectors when the 0 sector is bad Pin
bghuang23-May-05 22:41
bghuang23-May-05 22:41 
AnswerRe: How to read the floppy sectors when the 0 sector is bad Pin
Bob Stanneveld23-May-05 23:12
Bob Stanneveld23-May-05 23:12 
GeneralRe: How to read the floppy sectors when the 0 sector is bad Pin
bghuang24-May-05 2:06
bghuang24-May-05 2:06 
GeneralRe: How to read the floppy sectors when the 0 sector is bad Pin
Bob Stanneveld24-May-05 2:29
Bob Stanneveld24-May-05 2:29 
Questionofstream writes strings instead of unsigned ints? Pin
Bob Stanneveld23-May-05 21:36
Bob Stanneveld23-May-05 21:36 
AnswerRe: ofstream writes strings instead of unsigned ints? Pin
toxcct23-May-05 21:53
toxcct23-May-05 21:53 
GeneralRe: ofstream writes strings instead of unsigned ints? Pin
Bob Stanneveld23-May-05 23:08
Bob Stanneveld23-May-05 23:08 
Hello,

I guess that I wasn't paying much attention when I was stripping the code of obsolete stuff. Here is the code as it now is:
<br />
std::ofstream file;<br />
file.open("Test.dat", std::ios::out | std::ios::trunc | std::ios::binary);<br />
<br />
for( unsigned int i = 0; i < 256; i++ )<br />
{<br />
file << static_cast<unsigned char>(i) << i * 100;<br />
}<br />



toxcct wrote:
moreover, you declare it as a char, that means that it will take a maximum value of 127 (char range is [-128; 127])... declare it as unsigned char

This doesn't matter very much since the bits that are written to the stream are always the same. On the application side, where the raw value is interpreted, it makes a difference, but on the disk its doesn't. Example:
A byte can take 256 diffenrent values 0x00 to 0xFF. If I write a 128 to the disk, it writes 0x80. If I overflow a signed char with one (0x7F + 0x01) this becomes a negative value (0x80 == -0). So the same value gets written to the disk.
I agree with you using code like that is very bad practice, but my little mistake in the code example doesn't affect the program at all.

Blog[^]
GeneralRe: ofstream writes strings instead of unsigned ints? Pin
toxcct23-May-05 23:13
toxcct23-May-05 23:13 
GeneralRe: ofstream writes strings instead of unsigned ints? Pin
Bob Stanneveld24-May-05 0:18
Bob Stanneveld24-May-05 0:18 
GeneralRe: ofstream writes strings instead of unsigned ints? Pin
toxcct24-May-05 0:57
toxcct24-May-05 0:57 
GeneralRe: ofstream writes strings instead of unsigned ints? Pin
Bob Stanneveld24-May-05 2:07
Bob Stanneveld24-May-05 2:07 
GeneralRe: ofstream writes strings instead of unsigned ints? Pin
toxcct24-May-05 2:16
toxcct24-May-05 2:16 
GeneralRe: ofstream writes strings instead of unsigned ints? Pin
Bob Stanneveld24-May-05 2:20
Bob Stanneveld24-May-05 2:20 
AnswerRe: ofstream writes strings instead of unsigned ints? Pin
nm_11424-May-05 11:36
nm_11424-May-05 11:36 
GeneralRe: ofstream writes strings instead of unsigned ints? Pin
Bob Stanneveld25-May-05 2:27
Bob Stanneveld25-May-05 2:27 
QuestionHow to stop resizing of spliiter windows Pin
nripun23-May-05 21:34
nripun23-May-05 21:34 
AnswerRe: How to stop resizing of spliiter windows Pin
Priyank Bolia25-May-05 0:18
Priyank Bolia25-May-05 0:18 
GeneralDisplay DIB when I have its handle (HBITMAP) Pin
ninck23-May-05 21:23
ninck23-May-05 21:23 
GeneralRe: Display DIB when I have its handle (HBITMAP) Pin
Flit24-May-05 2:07
Flit24-May-05 2:07 
GeneralRe: Display DIB when I have its handle (HBITMAP) Pin
ninck24-May-05 4:01
ninck24-May-05 4:01 
GeneralCalling VC dll in VB application Pin
Jangid23-May-05 21:18
Jangid23-May-05 21:18 
QuestionWhat are different method to load any image from file Pin
amrutajoshi23-May-05 21:04
amrutajoshi23-May-05 21:04 
AnswerRe: What are different method to load any image from file Pin
ThatsAlok23-May-05 21:12
ThatsAlok23-May-05 21:12 
GeneralRe: What are different method to load any image from file Pin
Stlan23-May-05 21:22
Stlan23-May-05 21:22 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.