hi
any one can help me plz ??
my code is about opening file as binary
then get data from file to edit
and rewrite data to file
this is the code:
#include <cstdlib>
#include <iostream>
#include<fstrea m>
#include<string >
#include<conio. h>
using namespace std;
int main()
{
int i=1,add=0;
string *marry=new string[i];
fstream file;
int spos=0,filepos1 =0,change=0;
string mline,newline;
file.open("test .txt",ios:: out|ios::in|ios ::binary);
while(!file.eof ()){
filepos1=file.t ellp();
//get line from file
getline(file,ml ine);
//copy new line from main line to edit
newline=mline;
//edit the line as string(replace VB with C++)
spos=newline.fi nd("vb");
while(spos!=str ing::npos){
newline.replace (spos,2,"c++");
spos=newline.fi nd("vb");
}
//Inject Lines to Memory In Dynamic Array
marry[add]=newline;
cout<<marry[add]<<endl;
add++;
i++;
}
file.close();
//Open the file to rewrite data from memory to it
file.open("test .txt",ios:: out|ios::in|ios ::binary|ios::t runc);
for(int j=0;j<add;j++){
file<<marry[j]<<endl;
}
file.close();
return 0;
}
Thanks
2 4827
hi
any one can help me plz ??
my code is about opening file as binary
then get data from file to edit
and rewrite data to file
this is the code:
#include <cstdlib>
#include <iostream>
#include<fstrea m>
#include<string >
#include<conio. h>
using namespace std;
int main()
{
int i=1,add=0;
string *marry=new string[i];
fstream file;
int spos=0,filepos1 =0,change=0;
string mline,newline;
file.open("test .txt",ios:: out|ios::in|ios ::binary);
while(!file.eof ()){
filepos1=file.t ellp();
//get line from file
getline(file,ml ine);
//copy new line from main line to edit
newline=mline;
//edit the line as string(replace VB with C++)
spos=newline.fi nd("vb");
while(spos!=str ing::npos){
newline.replace (spos,2,"c++");
spos=newline.fi nd("vb");
}
//Inject Lines to Memory In Dynamic Array
marry[add]=newline;
cout<<marry[add]<<endl;
add++;
i++;
}
file.close();
//Open the file to rewrite data from memory to it
file.open("test .txt",ios:: out|ios::in|ios ::binary|ios::t runc);
for(int j=0;j<add;j++){
file<<marry[j]<<endl;
}
file.close();
return 0;
}
Thanks
Hello,
No problems with the code. The problem lies with eof() function. Try some googling and check the problem.
hi vpawizard
i always got Error Writing To Memory message
i solved my problem by writing the edited line directly to another file
cose of :
if i want to work with large file size
my code can't inject all lines in memory or that's
will stop operating system
thank you for trying
but i still waiting for suggestions from any memper
bye
Sign in to post your reply or Sign up for a free account.
Similar topics |
by: Steve Bennett |
last post by:
Can anyone suggest a good tutorial for reading
and writing binary files in Perl or send me some tips or examples?
I tried using pack and unpack and seek and read
but things don't work as expected so I must be missing
some subtle details.
For example: I tried reading a .RAW image file (no header info) and
writing it back out
using seek read and print.
It almost worked but any part of the image that was black
|
by: Igor Shulgin |
last post by:
Hi!
What is standard and direct way (within Oracle 9.2 stored procedures)
for
writing binary data from Oracle to external file on disk?
We have tried to use UTL_FILE package, but it operates on files
consisting out of "line" of size no more than 32767 bytes and adds new_line
symbol upon closing files.
Also we checked out interMedia types and packages for writing BLOB to
disk but now we get stuck with some strange error messages.
|
by: Dmitry |
last post by:
Hi!
Does anybody know how to write binary data to registry?
The purpose is to store an boxed object into registry and to
restore it.
|
by: Peter Steele |
last post by:
I have a managed C++ project that contains a simple structure:
struct
{
<multiple members>
} mydata;
I want to write the contents of this structure out to disk retaining the
exactly binary data without any additional header information, and of course
be able to later read it back in. What's the best way to accomplish this?
|
by: Denise Smith |
last post by:
Hello,
I'm wondering if anyone can help me out here?
I want to be able to browse records in a database where one of the
fields contains an image.
I think I might have to extract the image to a byte array, write it to
a temp file then refer to the temp file as the URL source for the
Image control.
| |
by: Vertilka |
last post by:
I need to read binary data file written by C++ program, using my C#
application.
How do i marshal the bytes i read with my C# code to .NET types.
The data is numbers (integers float doubles etc..) and strings.
I looked at the Marshal class but did not know how to use it with file.
Please add few code lines.
Thanks alot
|
by: cesco |
last post by:
Hi,
I have a binary file containing 1000 floating point numbers. I want to
load that file into an array. A way to do it could be the following:
>>> import array
>>> data = array.array('f')
>>> f = open('FileName.bin', 'rb')
>>> data.fromfile(f, 1000)
|
by: RML |
last post by:
Hi,
I have a MFC C++ application which write the data in a structure out to a
file. Here is the structure...
typdef struct {
short ID;
TCHAR Num;
short x;
} TestStruct;
|
by: Carl Forsman |
last post by:
I have some binary data encoded as Base64 encoding in an XML element
like this:
<data>TWFuIGlzIGRpc3Rpbmd1aXNoZWQsIG5vdCBvbmx</data>
how can I extract this data -
TWFuIGlzIGRpc3Rpbmd1aXNoZWQsIG5vdCBvbmx
and save to a file say test2.xml
|
by: Oralloy |
last post by:
Hello folks,
I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>".
The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed.
This is as boiled down as I can make it.
Here is my compilation command:
g++-12 -std=c++20 -Wnarrowing bit_field.cpp
Here is the code in...
|
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,...
| |
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...
|
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...
|
by: isladogs |
last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 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 a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules.
He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms.
Adolph will...
|
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();...
|
by: adsilva |
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
|
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
| |
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...
| | |