473,385 Members | 1,429 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.

how to insert tow byte in front of a file

(Hi to all... ^_^)

I tryed theese ways:

fstream riaperto( "codici.dat", ios::out|ios::binary|ios::app);
if(riaperto.bad()){
cerr<<"errore di apertura"<<endl;
system("Pause");
}

riaperto.seekp(ios::beg);
riaperto.put(char(nbyte/256));
riaperto.put(char(nbyte%256));

^= This one writes the bytes at the end of the file (allright, it's the
"app") .

ofstream riaperto( "codici.dat", ios::out|ios::binary);
if(riaperto.bad()){
cerr<<"errore di apertura"<<endl;
system("Pause");
}

riaperto.seekp(ios::beg);
riaperto.put(char(nbyte/256));
riaperto.put(char(nbyte%256));

This one it writes at the beginning but, then, the file contains only that
tow bytes... (overwrite)

What can i do?

Thanks in advance..

Gnafu


Jun 18 '06 #1
10 2638
Gnafu wrote:
(Hi to all... ^_^)

I tryed theese ways:

fstream riaperto( "codici.dat", ios::out|ios::binary|ios::app);
if(riaperto.bad()){
cerr<<"errore di apertura"<<endl;
system("Pause");
}

riaperto.seekp(ios::beg);
riaperto.put(char(nbyte/256));
riaperto.put(char(nbyte%256));

^= This one writes the bytes at the end of the file (allright, it's the
"app") .

ofstream riaperto( "codici.dat", ios::out|ios::binary);
if(riaperto.bad()){
cerr<<"errore di apertura"<<endl;
system("Pause");
}

riaperto.seekp(ios::beg);
riaperto.put(char(nbyte/256));
riaperto.put(char(nbyte%256));

This one it writes at the beginning but, then, the file contains only
that
tow bytes... (overwrite)

What can i do?

Thanks in advance..


Write the new bytes you want to a temporary file, then copy the content of
the original file over. If that was successful, rename the temporary file
to the name of the original.

Jun 18 '06 #2
In article <e7*************@news.t-online.com>,
ra******@t-online.de says...

[ ... ]
Write the new bytes you want to a temporary file, then copy the content of
the original file over. If that was successful, rename the temporary file
to the name of the original.


....and hope there are no other hard links to the file --
because if there are, you now have two separate files,
and all of the other hard links point to the unmodified
file.

--
Later,
Jerry.

The universe is a figment of its own imagination.
Jun 18 '06 #3
> Write the new bytes you want to a temporary file, then copy the content of
the original file over. If that was successful, rename the temporary file
to the name of the original.


I wanted to not do that.... :(
Ok, thank anyway..
Jun 18 '06 #4
Jerry Coffin wrote:
In article <e7*************@news.t-online.com>,
ra******@t-online.de says...

[ ... ]
Write the new bytes you want to a temporary file, then copy the content
of the original file over. If that was successful, rename the temporary
file to the name of the original.


...and hope there are no other hard links to the file --
because if there are, you now have two separate files,
and all of the other hard links point to the unmodified
file.


That's one of the reasons to better use symlinks ;-)

Jun 18 '06 #5
* Rolf Magnus:
Jerry Coffin wrote:
In article <e7*************@news.t-online.com>,
ra******@t-online.de says...

[ ... ]
Write the new bytes you want to a temporary file, then copy the content
of the original file over. If that was successful, rename the temporary
file to the name of the original.

...and hope there are no other hard links to the file --
because if there are, you now have two separate files,
and all of the other hard links point to the unmodified
file.


That's one of the reasons to better use symlinks ;-)


Depends on the OS. Windows supports hardlinks for files, symlinks for
directories, and shortcuts (which are like symlinks but not
automatically resolved) for anything. The rename approach might be
appropriate when safety against file content destruction is important,
you're guaranteed that no other process will create that file in the
span between its deletion and recreation by your program, and efficiency
is valued more than link preservation.

I think it should be a user-selectable option.

Follow-ups to [comp.programming].

--
A: Because it messes up the order in which people normally read text.
Q: Why is it such a bad thing?
A: Top-posting.
Q: What is the most annoying thing on usenet and in e-mail?
Jun 18 '06 #6
You'll need to put "POSIX compliant system" on your product
requirements box for doing this:

i = open ("blarg", O_WRONLY);
lseek(i, 0, SEEK_SET);
write(i, my_buffer, 2);
close(i);

Gnafu wrote:
(Hi to all... ^_^)

I tryed theese ways:

fstream riaperto( "codici.dat", ios::out|ios::binary|ios::app);
if(riaperto.bad()){
cerr<<"errore di apertura"<<endl;
system("Pause");
}

riaperto.seekp(ios::beg);
riaperto.put(char(nbyte/256));
riaperto.put(char(nbyte%256));

^= This one writes the bytes at the end of the file (allright, it's the
"app") .

ofstream riaperto( "codici.dat", ios::out|ios::binary);
if(riaperto.bad()){
cerr<<"errore di apertura"<<endl;
system("Pause");
}

riaperto.seekp(ios::beg);
riaperto.put(char(nbyte/256));
riaperto.put(char(nbyte%256));

This one it writes at the beginning but, then, the file contains only that
tow bytes... (overwrite)

What can i do?

Thanks in advance..

Gnafu


Jun 18 '06 #7
please don't top-post.

hdante wrote:
Yo> Gnafu wrote:
(Hi to all... ^_^)

I tryed theese ways:

fstream riaperto( "codici.dat", ios::out|ios::binary|ios::app);
if(riaperto.bad()){
cerr<<"errore di apertura"<<endl;
system("Pause");
}

riaperto.seekp(ios::beg);
riaperto.put(char(nbyte/256));
riaperto.put(char(nbyte%256));

^= This one writes the bytes at the end of the file (allright, it's the
"app") .

ofstream riaperto( "codici.dat", ios::out|ios::binary);
if(riaperto.bad()){
cerr<<"errore di apertura"<<endl;
system("Pause");
}

riaperto.seekp(ios::beg);
riaperto.put(char(nbyte/256));
riaperto.put(char(nbyte%256));

This one it writes at the beginning but, then, the file contains only
that
tow bytes... (overwrite)

What can i do?


u'll need to put "POSIX compliant system" on your product
requirements box for doing this:

i = open ("blarg", O_WRONLY);
lseek(i, 0, SEEK_SET);
write(i, my_buffer, 2);
close(i);


This will not insert two bytes at the beginning. Rather it overwrites the
first two bytes.
Jun 19 '06 #8
What does "top-post" mean ?

I'm sorry, I thought that's what he wanted.

Rolf Magnus wrote:
please don't top-post.

hdante wrote:
Yo> Gnafu wrote:
(Hi to all... ^_^)

I tryed theese ways:

fstream riaperto( "codici.dat", ios::out|ios::binary|ios::app);
if(riaperto.bad()){
cerr<<"errore di apertura"<<endl;
system("Pause");
}

riaperto.seekp(ios::beg);
riaperto.put(char(nbyte/256));
riaperto.put(char(nbyte%256));

^= This one writes the bytes at the end of the file (allright, it's the
"app") .

ofstream riaperto( "codici.dat", ios::out|ios::binary);
if(riaperto.bad()){
cerr<<"errore di apertura"<<endl;
system("Pause");
}

riaperto.seekp(ios::beg);
riaperto.put(char(nbyte/256));
riaperto.put(char(nbyte%256));

This one it writes at the beginning but, then, the file contains only
that
tow bytes... (overwrite)

What can i do?


u'll need to put "POSIX compliant system" on your product
requirements box for doing this:

i = open ("blarg", O_WRONLY);
lseek(i, 0, SEEK_SET);
write(i, my_buffer, 2);
close(i);


This will not insert two bytes at the beginning. Rather it overwrites the
first two bytes.


Jun 19 '06 #9
hdante wrote:
Rolf Magnus wrote:
please don't top-post.

What does "top-post" mean ?


It means that you are writing your text above the text you're answering to
instead of in a chronological order. I'll quote from Alf P. Steinbach's
signature:

A: Because it messes up the order in which people normally read text.
Q: Why is it such a bad thing?
A: Top-posting.
Q: What is the most annoying thing on usenet and in e-mail?

You should write your answers below the original text and directly below the
part that you are answering to. Also snip away parts that are not relevant
to your answer.

Jun 19 '06 #10
hdante <hd****@gmail.com> wrote:
What does "top-post" mean ?


http://en.wikipedia.org/wiki/Top_posting

Your responses should be interspersed thoughout the trimmed quoted text.

--
Marcus Kwok
Replace 'invalid' with 'net' to reply
Jun 19 '06 #11

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

Similar topics

1
by: Phil Powell | last post by:
I have to get this done by tonight! I have a .CSV file and a PHP file where I am inserting the values of the CSV file into the db table. See the results live:...
2
by: Atz | last post by:
Hi to all ! Im using MySql front and PHP 5 for some web shop. I didn't try it so far but i guess that the online data insertation ( accept costs and time ) should be the same process like for...
16
by: Philip Boonzaaier | last post by:
I want to be able to generate SQL statements that will go through a list of data, effectively row by row, enquire on the database if this exists in the selected table- If it exists, then the colums...
1
by: Abareblue | last post by:
I have no clue on how to insert a record into access. here is the whole thing using System; using System.Drawing; using System.Collections; using System.ComponentModel;
11
by: Chris Fink | last post by:
I have setup an Oracle table which contains a blob field. How do I insert data into this field using C# and ADO.net?
1
by: kyo guan | last post by:
Hi : python list object like a stl vector, if insert a object in the front or the middle of it, all the object after the insert point need to move backward. look at this code ( in python...
3
by: Me | last post by:
Trying to get the current status of the insert key. Found my.computer.keyboard.capslock, but no such item for insert key. Anyone have some code to help. Can't figure out getkeystate. compiler...
1
by: deepaks85 | last post by:
Dear Friends, If I have a text file more than 8 byte or upto 100 byte, how can I insert the data of that text file into mysql table. As per as I am concern there is not any datatype more than 4...
4
by: ansuhua | last post by:
I need save huge data in a file in byte format.Sometimes i have to insert some bytes in a special position.I use FileStream,but i can only append byte at the end of the file or rewrite data in the...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
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...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
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...

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.