writing to a file

Hi, when you have to write data on a file in binary mode multiple times (without closing the file), is the put pointer left where you ended writing the last time, or do you have to use tellp() or seekp() again and again to make sure you write at the right place?

Thanks,
AeonFlux

[edit] hmm.... I would have the same question about the get pointer, does he stay in place after you're done reading something (without closing the file, of course), or do you have to set it back at the right place with seekg() ??
Last edited on
is the put pointer left where you ended writing the last time

Yes. It works the same way with reading/get pointer.
> is the put pointer left where you ended writing the last time
> I would have the same question about the get pointer, does he stay in place after you're done reading something

If you are mixing input and output on the same stream:

std::filebuf does not maintain separate positions for the input sequence and the output sequence. An input operation would affect both get and the put positions; and vice versa.

The restrictions on reading and writing a sequence controlled by an object of class basic_filebuf are the same as for reading and writing with the Standard C library FILEs.

In particular:
...
A joint file position is maintained for both the input sequence and the output sequence.
Problem 1:
Write a program that prompts the user to enter his personal information including: his first
name, his age, his job title, his salary, and his car brand. Store all these information in
variables with suitable data types. Then ask the user to enter any character from: a, b, c, d.
based on that your program will do the following:
 If the user entered a: your program will call a function call reflect, this function takes
the user first name as an input, and the it print the first name in opposite order starting
with the last character till reaching the first without spaces between the characters.
 If the user entered b: you program will call a function called raise, this function takes
the user salary and increases it with 500 jd, after returning to the main print the new
salary for the user on the screen.
Page 2 of 2
 If the user entered c: your program will print the car brand on screen.
 If the user entered d: your program will call a function called mix, this function will
print each character in the job title for number of times equals the user age, each
character will be printed on a separate line.
pleasssss who could solve it for me im so tired from trying if any would like to help me send it to my email (daliafakhri@hotmail.com)
Last edited on
hmm looks like you have an "array of char" problem... http://www.cplusplus.com/doc/tutorial/ntcs/

:-)

this is easy... you need to take a look at the <string> class... functions, etc...



Also thanks to you guys up there it clarifies things... :-)

AeonFlux
Topic archived. No new replies allowed.