473,385 Members | 1,944 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 write to a file without deleting information in it

using c++ in files:
when using ios::out mode for an old file,which is to be changed once again,(not only at the end),the old information in the file is getting deleted.what operation should we use to open and write into any old file without deleting the old information...please reply.
Sep 23 '10 #1
7 3677
Banfa
9,065 Expert Mod 8TB
either move the output pointer to the end of the file before writing or use ios::ate to do it as you open.
Sep 23 '10 #2
thanks for that...but even on using ios::ate operation,i am unable to add my data without getting the old data deleted..can u please give me a sample progrm for that??
Sep 24 '10 #3
Banfa
9,065 Expert Mod 8TB
No but you could post the code you are using.
Sep 24 '10 #4
Expand|Select|Wrap|Line Numbers
  1. #include<iostream>
  2. #include<fstream>
  3. using namespace std;
  4. int main()
  5. {
  6. fstream f;
  7. f.open("sai",ios::out|ios::ate);
  8. f<<"shskkhdljd;kdkd";
  9. f.close();
  10. fstream f1;
  11. f1.open("sai",ios::out|ios::ate);
  12. f1.seekp(4);
  13. f1<<"sai";
  14. f1.close();
  15. return 0;
  16. }

here actually the old record should remain,but even on using ios::ate,it is getting deleted..
Sep 26 '10 #5
Banfa
9,065 Expert Mod 8TB
Instead of "ios::out|ios::ate" try "ios_base::out"
Sep 26 '10 #6
i am using ubuntu os(terminal) for compiling my programs.....when i am using ios::nocreate to open my file...." error: ‘nocreate’ is not a member of ‘std::ios’" ...this error is getting displayed .is there any problem with my compiler??
Sep 28 '10 #7
Banfa
9,065 Expert Mod 8TB
That is because ios::nocreate and for that matter ios_base::nocreate are not part of the standard.
Sep 28 '10 #8

Sign in to post your reply or Sign up for a free account.

Similar topics

2
by: Mike | last post by:
I am sure that I am making a simple boneheaded mistake and I would appreciate your help in spotting in. I have just installed apache_2.0.53-win32-x86-no_ssl.exe php-5.0.3-Win32.zip...
44
by: Xah Lee | last post by:
here's a large exercise that uses what we built before. suppose you have tens of thousands of files in various directories. Some of these files are identical, but you don't know which ones are...
0
by: Tom Lee | last post by:
Hi, I'm new to .NET 2003 compiler. When I tried to compile my program using DEBUG mode, I got the following errors in the C:\Program Files\Microsoft Visual Studio .NET 2003\Vc7 \include\xdebug...
18
by: JKop | last post by:
Here's what I know so far: You have a C++ project. You have source files in it. When you go to compile it, first thing the preprocessor sticks the header files into each source file. So now...
3
by: pooja | last post by:
Suppose i have created a class c1 with f1()in c1.cpp and included this c1.cpp in file1.cpp file , which is also having main() by giving the statement #include "c1.cpp". the same i can do by...
7
by: Corepaul | last post by:
Missing Help Files When I enter "recordset" as the keyword and search the Visual Basic Help index, I get many topics of interest in the resulting list. But there isn't any information available...
11
by: ambika | last post by:
Iam just trying to know "c". And I have a small doubt about these header files. The header files just contain the declaration part...Where is the definition for these declarations written??And how...
18
by: UJ | last post by:
Folks, We provide custom content for our customers. Currently we put the files on our server and people have a program we provide that will download the files. These files are usually SWF, HTML or...
0
by: wal | last post by:
How does one attach files to emails using libgmail? The following code http://pramode.net/articles/lfy/fuse/4.txt works fine when said files are simple text files, but it failes as soon as the...
3
by: aRTx | last post by:
I have try a couple of time but does not work for me My files everytime are sortet by NAME. I want to Sort my files by Date-desc. Can anyone help me to do it? The Script <? /* ORIGJINALI
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...
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: 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:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...

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.