473,385 Members | 1,661 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

File's Openmode and the Cursor position

I hope everybody is having a fantastic X-Mas, I will hate you for that
since I have to be at the computer trying to keep my current job, grrr.
:)
OK, folks, jokes aside I have a question that might sound a bit dumb,
but I am just trying to confirm something, here I go. When opening a
'std::fstream' with the following mode:
std::ios_base::out | std::ios_base::app
I expect the cursor position at the end of the file, am I right here?

I am asking 'cos after I open the file stream, I retrieve its cursor
position which is always at zero; no matter what the size of the file
is.
I have overcome the problem by finding the file size and then setting
the cursor at the end of the file, but this would be a work around. The
proper way would be for the 'std' to place the cursor at the end of the
file, since the file has been opened for writing, no?

Gracias muchacho y muchachas, party on!

Dec 28 '05 #1
3 2245
Al-Burak wrote:
I hope everybody is having a fantastic X-Mas, I will hate you for that
since I have to be at the computer trying to keep my current job, grrr.
:)
OK, folks, jokes aside I have a question that might sound a bit dumb,
but I am just trying to confirm something, here I go. When opening a
'std::fstream' with the following mode:
std::ios_base::out | std::ios_base::app
I expect the cursor position at the end of the file, am I right here?

I am asking 'cos after I open the file stream, I retrieve its cursor
position which is always at zero; no matter what the size of the file
is.
I have overcome the problem by finding the file size and then setting
the cursor at the end of the file, but this would be a work around. The
proper way would be for the 'std' to place the cursor at the end of the
file, since the file has been opened for writing, no?

Gracias muchacho y muchachas, party on!

Hi,

Could you please show us the code you have, which does not work as you
expect?

Regards,
Peter Jansson
Dec 28 '05 #2
pH
You may find that even though the cursor position does not appear to be
at the end, writing to the file causes the data to be written after the
rest of the file, even without you explicity seeking to the end.

But, as Peter says, post some code !

Dec 28 '05 #3
Al-Burak wrote:
'std::fstream' with the following mode:
std::ios_base::out | std::ios_base::app
I expect the cursor position at the end of the file, am I right here?


No, you are not right. The mode 'app' causes the stream to append to
the file but it does not necessarily cause positioning the current
position to the end. This is what 'ate' is for: this mode puts the
initial position at the end of the file. Possibly you want a combination
of 'ate' and 'app' but actually why bother with the position at all?
'app' should always append to the file independent of what the initial
file position is. What is your actual problem?
--
<mailto:di***********@yahoo.com> <http://www.dietmar-kuehl.de/>
<http://www.eai-systems.com> - Efficient Artificial Intelligence
Dec 28 '05 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

10
by: Steve | last post by:
Hi, I'm trying to read a binary file into a buffer: std::ifstream ifs(fileName, std::ios::in|std::ios::binary); if (!ifs) return; ifs.seekg(0,std::ios::end); int len = ifs.tellg();...
11
by: Skc | last post by:
I have a .txt which has been exported as a .csv from an external source. What i need to do is to import this into SQL2000 (into a table) but I need to do special things on the data: 1. I need to...
1
by: Dan H. | last post by:
Hello, I want to try to retrieve the cursor position x and y relative to the form the cursor is over. The way I am doing it now is: 1. Retrieve the left and top position of the form relative...
1
by: Tantra Veda | last post by:
Hello C# gurus, I have a question about finding cursor position in NumericUpDown control. On my form I have a numericUpDown control with 2 decimal places. I want to increment value in the numeric...
1
by: objectref | last post by:
Hi to all, we have the MousePosition property that we can get the Point of the position of the mouse cursor on the screen, but is it there a way to get the respective Point of a cursor in a...
9
by: Sandy | last post by:
can mfc application, send text data to opened notepad file in desktop?(live transfer of data) . can anybody help
14
by: Gary Nelson | last post by:
Anyone have any idea why this code does not work? FileOpen(1, "c:\JUNK\MYTEST.TXT", OpenMode.Binary, OpenAccess.ReadWrite, OpenShare.Shared) Dim X As Integer For X = 1 To 26 FilePut(1, Chr(X +...
12
by: imme929 | last post by:
How do I do it? Nothing in the books is helpful. I need to save a structure with different data types.
4
by: mike | last post by:
I have the opportunity to rescue a project that uses a mouse to sense the relative position of a machine. The hardware is built...just needs to be programmed. Stop snickering!!! I didn't do it...I...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.