Click here to Skip to main content
15,914,392 members
Home / Discussions / C / C++ / MFC
   

C / C++ / MFC

 
GeneralRe: Unable to paste clipboard data by sending WM_PASTE message Pin
lazy_panther4-Feb-10 1:50
lazy_panther4-Feb-10 1:50 
GeneralRe: Unable to paste clipboard data by sending WM_PASTE message Pin
LunaticFringe4-Feb-10 13:32
LunaticFringe4-Feb-10 13:32 
QuestionTroublesome Handling of Files in C++ Pin
Sujan Dhakal3-Feb-10 1:29
Sujan Dhakal3-Feb-10 1:29 
AnswerRe: Troublesome Handling of Files in C++ Pin
CPallini3-Feb-10 1:37
mveCPallini3-Feb-10 1:37 
AnswerRe: Troublesome Handling of Files in C++ [modified] Pin
Stuart Dootson3-Feb-10 1:46
professionalStuart Dootson3-Feb-10 1:46 
GeneralRe: Troublesome Handling of Files in C++ Pin
CPallini3-Feb-10 1:54
mveCPallini3-Feb-10 1:54 
GeneralRe: Troublesome Handling of Files in C++ Pin
Stuart Dootson3-Feb-10 2:28
professionalStuart Dootson3-Feb-10 2:28 
AnswerRe: Troublesome Handling of Files in C++ Pin
Raj Indian3-Feb-10 22:00
Raj Indian3-Feb-10 22:00 
fstream::eof() - returns true if the 'eofbit' has been set by a previous i/o operation.
fstream::read(s, n) - sets 'eofbit' if the End-of-File is reached before n characters have been read.

The file has only 5 characters and the while loop will execute twice. In the first pass you try to read 5 bytes and it will be success. In the second pass read will fail and sets the 'eofbit'. Since you are not checking how many bytes read, you cout the old buffer contents again.
This is the reason why you got "abcfabcf".

The code can be changed to print "abcf" once, by checking the bytes read using fstream::gcount() as
.................
if(file.is_open())
{
//file.write(data,sizeof(data));
while(!file.eof())
{
file.read(data,sizeof(data));
if(file.gcount())
cout<<data;
}
file.close();
}
..................
QuestionSetUpAndDeployment Project Pin
jannathali2-Feb-10 22:31
jannathali2-Feb-10 22:31 
AnswerRe: SetUpAndDeployment Project [modified] Pin
KingsGambit2-Feb-10 23:47
KingsGambit2-Feb-10 23:47 
GeneralRe: SetUpAndDeployment Project Pin
jannathali3-Feb-10 1:03
jannathali3-Feb-10 1:03 
GeneralRe: SetUpAndDeployment Project Pin
KingsGambit3-Feb-10 1:14
KingsGambit3-Feb-10 1:14 
QuestionCaption Change Pin
john56322-Feb-10 20:32
john56322-Feb-10 20:32 
AnswerRe: Caption Change Pin
Richard MacCutchan2-Feb-10 22:34
mveRichard MacCutchan2-Feb-10 22:34 
AnswerRe: Caption Change Pin
CPallini2-Feb-10 22:42
mveCPallini2-Feb-10 22:42 
AnswerRe: Caption Change Pin
Moak3-Feb-10 1:12
Moak3-Feb-10 1:12 
QuestionHow to disable LNK4099 warning in debug build Pin
Chesnokov Yuriy2-Feb-10 20:19
professionalChesnokov Yuriy2-Feb-10 20:19 
AnswerRe: How to disable LNK4099 warning in debug build Pin
«_Superman_»2-Feb-10 20:46
professional«_Superman_»2-Feb-10 20:46 
QuestionRe: How to disable LNK4099 warning in debug build Pin
Chesnokov Yuriy2-Feb-10 21:20
professionalChesnokov Yuriy2-Feb-10 21:20 
AnswerRe: How to disable LNK4099 warning in debug build Pin
Dr. Frank Heimes7-Feb-11 22:00
Dr. Frank Heimes7-Feb-11 22:00 
QuestionHow can identified Any Process run by admin or by any other user? Pin
Le@rner2-Feb-10 18:27
Le@rner2-Feb-10 18:27 
AnswerRe: How can identified Any Process run by admin or by any other user? Pin
«_Superman_»2-Feb-10 18:45
professional«_Superman_»2-Feb-10 18:45 
AnswerRe: How can identified Any Process run by admin or by any other user? Pin
KingsGambit2-Feb-10 18:48
KingsGambit2-Feb-10 18:48 
AnswerRe: How can identified Any Process run by admin or by any other user? Pin
Kushagra Tiwari3-Feb-10 0:37
Kushagra Tiwari3-Feb-10 0:37 
QuestionRequest Pin
Hans Dietrich2-Feb-10 17:55
mentorHans Dietrich2-Feb-10 17:55 

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.