Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / Languages / Managed C++ / July 2004

Tip: Looking for answers? Try searching our database.

Read data from files using fstreams

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
"José Manuel (JMN CandyBeat)" - 25 Jul 2004 15:52 GMT
Hello.

    I'm moving from Visual C++ 6.0 to Visual C++ .NET 2003 and I saw the
changes to the streams. I'm rewriting my code and finished doing it
yesterday.

    All seemed to be right, but the file reading.

    My old code has lines like the following function call:

    (file is a ifstream, var is a WORD, that is a typedef unsigned sort)
here is the line:

   
    file.read(&var, 2)

    Well, when this line is executed, the results are not what I'm looking
for: it reads inconsistent (arbitrary?) data. In my old code this line
worked. It is supposed to read 2 bytes from the file and asign them to
the WORD in var.

    For this reason, I think that Visual C++ 6.0 and .NET 2003 has some
slight differences for reading in the way I want to read.

    Maybe I'm not properly using the function. I mean... maybe I don't
understand well the mechanism in C++ to read BYTES, WORDS, DWORDS
UWORDS, etc.

    So I request your help and would be thankful is someboy teach me about
reading using standar C++ streams in this .NET 2003.

Thank you very much.
Igor Tandetnik - 26 Jul 2004 23:55 GMT
"Jos? Manuel (JMN CandyBeat)" <jmn@superjmn.com> wrote in message
news:uKPvMclcEHA.3044@TK2MSFTNGP10.phx.gbl
> My old code has lines like the following function call:
>
[quoted text clipped - 5 lines]
> Well, when this line is executed, the results are not what I'm looking
> for: it reads inconsistent (arbitrary?) data.

Are you opening the file in text mode (without ios::binary flag) by any
chance? What you see may be caused by CRLF to \n translation.
Signature

With best wishes,
   Igor Tandetnik

"For every complex problem, there is a solution that is simple, neat,
and wrong." H.L. Mencken

"José Manuel (JMN CandyBeat)" - 27 Jul 2004 15:35 GMT
>>My old code has lines like the following function call:
>>
[quoted text clipped - 8 lines]
> Are you opening the file in text mode (without ios::binary flag) by any
> chance? What you see may be caused by CRLF to \n translation.

Whops! I solved the problem, it's because I was reading the wrong
position in the file and that explains why the reads was incoherent!

(By the way, I was using ios::binary | ios::in)

Thank you!!

Rate this thread:







Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.