473,804 Members | 4,153 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

HELP! using filehandle.get( "filename") writes to file when it reads!?

Hi, I wonder if anyone could help me. I am moving accross from C to
C++ and am writing a program that reads and writes data into a file. I
am aware of the old C ways of doing it but am trying to use the C++
functions which don't seem to be working propperly.

I need to open the file for reading and writing because I want to
search for a possition in a file called settings.dat and then write a
number after a certain chatacter. However when I use
examplefile.get (buffer,100); or examplefile.get line(buffer,100 ), in
addition to reading to the file it also modifies it by inserting the
first three characters of what ot read back into the place it started
reading from. Does anyone know why this might be happening or how I
can get arround this? I am using Dev-C++.
I'll give this test program as an example, it requires any old file
called settings.dat

=============== =============== =============== ===
#include <iostream>
#include <fstream>


#define FSETTINGS "settings.d at"

using namespace std;

int main () {
char buffer[256];
//fstream examplefile;
fstream examplefile (FSETTINGS);
//examplefile.see kg(9,ios::cur);
examplefile.get (buffer,100);
cout << buffer << endl;

system ("PAUSE");
return 0;
}
=============== =============== =============== =============== ==
Jul 19 '05 #1
1 4009
Christopher Reeve wrote:
Hi, I wonder if anyone could help me. I am moving accross from C to
C++ and am writing a program that reads and writes data into a file. I
am aware of the old C ways of doing it but am trying to use the C++
functions which don't seem to be working propperly.

I need to open the file for reading and writing because I want to
search for a possition in a file called settings.dat and then write a
number after a certain chatacter. However when I use
examplefile.get (buffer,100); or examplefile.get line(buffer,100 ), in
addition to reading to the file it also modifies it by inserting the
first three characters of what ot read back into the place it started
reading from.
I don't understand what you said. But neither of those functions should
write to the file.
Does anyone know why this might be happening or how I
can get arround this? I am using Dev-C++.
I'll give this test program as an example, it requires any old file
called settings.dat

=============== =============== =============== ===
#include <iostream>
#include <fstream>
I suggest adding <string>

#define FSETTINGS "settings.d at"
It would be better if you used

const char *const fsettings = "settings.d at";

I changed the case because it is no longer a macro.

using namespace std;

int main () {
char buffer[256];
I suggest making this

string buffer;
//fstream examplefile;
fstream examplefile (FSETTINGS);
//examplefile.see kg(9,ios::cur);
examplefile.get (buffer,100);
I suggest using

getline(example file, buffer);

Where buffer is a string. Note that this is not exactly the same,
because it extracts the newline character from the stream (and discards
it) rather than leaving it there.
cout << buffer << endl;

system ("PAUSE");
return 0;
}
=============== =============== =============== =============== ==


I can't see an obvious reason for any serious problems. Your code worked
for me. You might need to give us more information, and the contents of
the input file you used for testing.

-Kevin
--
My email address is valid, but changes periodically.
To contact me please use the address from a recent posting.

Jul 19 '05 #2

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

Similar topics

7
4015
by: Kornelius Finkenbein | last post by:
Hello folks! I've got a strange problem with my download-script in conjunction with M$ internet explorer, if the filename I want to link to includes more than one points. In Netscape the problem doesn't exist. For example: input: ... download.php?name=virtualdub_1.4.9.zip
1
1520
by: Sameh Abdelatef | last post by:
Dear perl experts, I used to use to open and add new lines to $filename, but it didn't work any more. The perl version is 5.8.1. When I try it's work but the content of $filename is deletd. Any help will be appreciated.
2
2900
by: George Marsaglia | last post by:
I have a set of, say, 2000 points in the 8-dimensional simplex S={(x_1,x_2,...,x_8),x_1+x_2+...+x_8=1, x's>=0}. To help analyze that 8-dimensional set, I wish to project the set of points onto each of the 'faces' {x_i+x_j+x_k=1} for the 56 choices i,j,k, that is, i=1 to 6; j=i+1 to 7; k=j+1 to 8. Finally, use gnuplot to load and plot each of the 56 files of 3-d points. I have C code that will, for given i,j,k, find the projection...
0
6281
by: Rob Meade | last post by:
Hi all, I've written a small app which firstly reads in from an xml config file to set some start parameters. once this is done, it takes the supplied path from the config file, iterates through it finding each .ini file, and parses each one. It basically strips out lines I dont want. When it gets to the end it's supposed to write the file back with the
8
2490
by: Seth Darr | last post by:
I'm working on migrating an Classic ASP/VB6 COM application from an NT Server with IIS<6 to an virtual machine running Windows Server 2003 and IIS 6. I've worked through most of the obvious problems resulting from IIS 6 prohibiting ASP and SSI etc, but I've hit a peculiar wall. One ASP page uses a VB6 COM object that basically reads from an .INI file and uses it to open another file. The existing code uses this line (in VB6) to do this:...
0
2853
by: smanisankar | last post by:
hi, the following is the full page code for uploading a file to server. since i got no idea to overwrite the file, i want delete the file if the file is already uploaded. i got the folder name and filename of the file to delete from the request.QueryString("path") so i got the above error when i try to delete the file before upload. Please anyone help me to solve out from this error. <%@ Import Namespace="System.IO" %>
0
1065
by: eddie69 | last post by:
Hi, My application has a Toolstrip with a Help button which launches a htm help file. It works fine when the system's default browser is IE. When Firefox is set as default, the application complains with an exection error: ************** Exception Text ************** System.ComponentModel.Win32Exception: The system cannot find the file specified at System.Diagnostics.Process.StartWithShellExecuteEx(ProcessStartInfo startInfo) at...
0
4965
by: Radu | last post by:
Hi. I have finished a web-site - and it runs fine on my dev machine. I have deployed it onto the server, and now I have this (which, by the way, doesn't seem to happen all the time - sometimes I can see other errors): _______________________________________________ Description: An error occurred during the processing of a configuration file required to service this request. Please review the specific error details below and modify your...
1
2807
by: Webstorm | last post by:
Hi, I hope someone can help me sort this out a bit, Im completely lost. Here is the page I am working on: http://www.knzbusinessbrokers.com/default.asp I have 3 search critera that I need to use when querying the database. Right now it is only looking for a match on one of those dropdowns and not all 3. can anyone help? Here is the code: <form BOTID="0" METHOD="POST" action="businessforsale_interface/Results/test3.asp">
0
10338
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
10323
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
10082
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
9161
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
6856
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5658
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4301
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
3823
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2997
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.