Thread overview |
---|
April 10, 2016 Set cursor position in a file | ||||
---|---|---|---|---|
| ||||
Hello, Is there the possibility to set the cursor position in a file ? Example: -------------------- void main() { File myFile = File("myFile.txt"); showFile(myFile); // set cursor pos to 0 showFile(myFile); } void showFile(File f) { while (!f.eof()) { write(f.readln()); } } -------------------- Thanks in advance. |
April 10, 2016 Re: Set cursor position in a file | ||||
---|---|---|---|---|
| ||||
Posted in reply to Lucien | On Sunday, 10 April 2016 at 16:19:51 UTC, Lucien wrote:
> Hello,
>
> Is there the possibility to set the cursor position in a file ?
>
> Example:
> --------------------
> void main()
> {
> File myFile = File("myFile.txt");
>
> showFile(myFile);
>
> // set cursor pos to 0
>
> showFile(myFile);
> }
>
> void showFile(File f)
> {
> while (!f.eof())
> {
> write(f.readln());
> }
> }
> --------------------
>
> Thanks in advance.
See std.stdio.File.seek.
For your example, if all you want to do is to write a file to std.out:
---
import std.file : read;
import std.stdio : write;
string file = cast(string) read("filename.txt");
write(file);
---
|
April 10, 2016 Re: Set cursor position in a file | ||||
---|---|---|---|---|
| ||||
Posted in reply to deed | On Sunday, 10 April 2016 at 16:46:02 UTC, deed wrote:
> On Sunday, 10 April 2016 at 16:19:51 UTC, Lucien wrote:
>> Hello,
>>
>> Is there the possibility to set the cursor position in a file ?
>>
>> Example:
>> --------------------
>> void main()
>> {
>> File myFile = File("myFile.txt");
>>
>> showFile(myFile);
>>
>> // set cursor pos to 0
>>
>> showFile(myFile);
>> }
>>
>> void showFile(File f)
>> {
>> while (!f.eof())
>> {
>> write(f.readln());
>> }
>> }
>> --------------------
>>
>> Thanks in advance.
>
> See std.stdio.File.seek.
>
> For your example, if all you want to do is to write a file to std.out:
> ---
> import std.file : read;
> import std.stdio : write;
>
> string file = cast(string) read("filename.txt");
> write(file);
> ---
Thanks !
so: f.seek(0 , SEEK_SET);
|
Copyright © 1999-2021 by the D Language Foundation