Overview
Examples
Screenshots
Comparisons
Applications
Download
Documentation
Tutorials
Bazaar
Status & Roadmap
FAQ
Authors & License
Forums
Funding Ultimate++
Search on this site
Search in forums












SourceForge.net Logo
Home » Community » Newbie corner » Open file as stream for fgetpos(), fseek(), etc.
Open file as stream for fgetpos(), fseek(), etc. [message #29697] Tue, 09 November 2010 02:43 Go to next message
nlneilson is currently offline  nlneilson
Messages: 644
Registered: January 2010
Location: U.S. California. Mojave &...
Contributor
I am using the file chooser in upp.
FileIn in((String)fn);

What is the best way in upp to open the file as a stream:
FILE *fp;
or
ifstream infile (fp);


so these C++ functions can be used:
fgetpos(), fseek(), fseeko(), fsetpos(), ftell() and ftello()

and still use:
while(!in.IsEof()){
Ln = in.GetLine();
or something similar to get the lines.

[Updated on: Tue, 09 November 2010 03:09]

Report message to a moderator

Re: Open file as stream for fgetpos(), fseek(), etc. [message #29698 is a reply to message #29697] Tue, 09 November 2010 06:20 Go to previous messageGo to next message
dolik.rce is currently offline  dolik.rce
Messages: 1789
Registered: August 2008
Location: Czech Republic
Ultimate Contributor

Hi Neil,
Do you really need to use the C++ functions? Why not just use the FileIn::Seek() and FileIn::GetPos(), do you miss some functionality in them?

Honza
Re: Open file as stream for fgetpos(), fseek(), etc. [message #29700 is a reply to message #29698] Tue, 09 November 2010 07:05 Go to previous messageGo to next message
nlneilson is currently offline  nlneilson
Messages: 644
Registered: January 2010
Location: U.S. California. Mojave &...
Contributor
I had no idea that upp had FileIn::Seek() and FileIn::GetPos().

After getting Vista to search, I had previously had turned off indexing as it took too much CPU and had to change settings in search tools, the upp directory (which includes any help files shipped with upp) found fseek.

Can this be found in the "Manual" in the left sidebar of the forum?

I did make some progress with:
ifstream inFile("test1.txt");
getline (in,Lnn);

An interesting thing there was getline returns a string
but Ln = in.GetLine(); returns a String
upp has a capital S
C++ has small s
The compiler error let me know.

Does upp have functions for fseeko(), fsetpos(), ftell() and ftello()?

upp and this forum are great, the documentation is lacking for those just getting into it.

edit: If someone could put the "Manual" in a .zip or .tar that would be great help. If it's a matter of where to place and serve it I have a website that in more than 2 years has never used more than 10%.

[Updated on: Tue, 09 November 2010 07:22]

Report message to a moderator

Re: Open file as stream for fgetpos(), fseek(), etc. [message #29701 is a reply to message #29700] Tue, 09 November 2010 07:24 Go to previous messageGo to next message
dolik.rce is currently offline  dolik.rce
Messages: 1789
Registered: August 2008
Location: Czech Republic
Ultimate Contributor

They can be found in Stream documentation, because they're part of the interface common to all Streams.

The fseeko function is not needed, it's only difference from fseek is the type of position parameter. The Seek() method takes int64 argument, so it is actually equivalent to fseeko64() and that should be suitable for anything. Similarly for ftello.

Now, IIRC ftell() essentially differs from fgetpos() only in fact that one returns number of characters and the other number of bytes, right? The same holds for fseek() and fsetpos(). The U++ streams always work with bytes, not characters and the same is true for String, so only the byte versions are usually necessary. If you work with multibyte characters, you will have to load them to WString first if you want to work with characters.

Windows search is and always has been a disaster. It is usually faster to search help in theide, or even search the uppsrc directory using "Search in files..." Wink

Honza
Re: Open file as stream for fgetpos(), fseek(), etc. [message #29702 is a reply to message #29701] Tue, 09 November 2010 07:52 Go to previous messageGo to next message
nlneilson is currently offline  nlneilson
Messages: 644
Registered: January 2010
Location: U.S. California. Mojave &...
Contributor
Thanks for taking the time to explain.

Much of the time I find a snip of code that works and just modify it. When I do dig into something the next time it is needed it has been forgotten.
Without my old code and any notes made it's a learning process again.
Re: Open file as stream for fgetpos(), fseek(), etc. [message #29704 is a reply to message #29697] Tue, 09 November 2010 09:52 Go to previous messageGo to next message
mr_ped is currently offline  mr_ped
Messages: 825
Registered: November 2005
Location: Czech Republic - Praha
Experienced Contributor
nlneilson: U++ being crossplatform platform means whenever you are looking at some basic C++ clib/POSIX function at thinking about using it, you should have warning bell in head saying "how does U++ wrap this?" and search for it first, or ask at forum. When you adopt this tactic, you will start straight with upp::Stream and save yourself some trouble later.

Although this approach locks you to U++, but then again, the source is here, so it's not that much of "lock". And benefits ... usually cleaner API, hiding platform specific details (like int vs int64 in clib file functions), and usually a nice interface to read things directly into NTL/[W]String and other Core types.

About searching it in help... I find it somewhat difficult too, I often try this web version first, but sometimes when I'm almost sure where to look, I include that package into my project and hit F1. With things like NTL and files it's quite easy to guess where to look, that's pure Core.

Funny thing, now I did notice in latest TheIDE build I can't click on any internal hyperlink in help (external leading to http:// works), only the tree on left works.
Re: Open file as stream for fgetpos(), fseek(), etc. [message #29706 is a reply to message #29704] Tue, 09 November 2010 10:35 Go to previous messageGo to next message
nlneilson is currently offline  nlneilson
Messages: 644
Registered: January 2010
Location: U.S. California. Mojave &...
Contributor
mr_ped wrote on Tue, 09 November 2010 09:52

...you should have warning bell in head saying "how does U++ wrap this?"

... usually cleaner API, hiding platform specific details


Good points!
Re: Open file as stream for fgetpos(), fseek(), etc. [message #29709 is a reply to message #29706] Tue, 09 November 2010 11:56 Go to previous message
nlneilson is currently offline  nlneilson
Messages: 644
Registered: January 2010
Location: U.S. California. Mojave &...
Contributor
Thanks Honza, got what I need, in.SeekCur(-2000);

About 40 bytes each line for 3D position, 1/sec.
To set the replay back 1 min (40*60)
in.SeekCur(-2400)

Works OK.

A file was used before for testing, CPU usage, responsiveness, etc for 50 concurrent traces for about 3 hours of data ~200k lines (8MB).
Fast forward was not a problem by skipping lines, in.SeekCur(4000000) could go to the midpoint faster.
Rewinding a set amount is a function that was not included before, now it can be.

Neil

[Updated on: Tue, 09 November 2010 12:01]

Report message to a moderator

Previous Topic: Few questions
Next Topic: Debugging
Goto Forum:
  


Current Time: Sat Apr 27 00:23:08 CEST 2024

Total time taken to generate the page: 0.05811 seconds