|
From: Noorez K. <coo...@ho...> - 2004-01-14 19:00:13
|
This is a code that should copy a .exe file. But i'm not sure what function
call to use to copy one bit at time. Can someone fill it in.
#include <iostream>
#include <cstdlib>
#include <fstream>
#include <string>
using namespace std;
int main()
{
ofstream out_file;
ifstream in_file;
cout << "Program copyer. The .exe extension will be added for you\n";
char name1[234];
cout << "Enter name of file: ";
cin.getline(name1, 234);
strcat(name1,".exe");
in_file.open(name1, ios::binary);
out_file.open("newfile.exe",ios::binary);
//code needed hear
system("pause");
}
_________________________________________________________________
Add photos to your e-mail with MSN 8. Get 2 months FREE*.
http://join.msn.com/?page=features/photos&pgmarket=en-ca&RU=http%3a%2f%2fjoin.msn.com%2f%3fpage%3dmisc%2fspecialoffers%26pgmarket%3den-ca
|
|
From: Noorez K. <lor...@ho...> - 2005-06-15 18:18:45
|
I'm having some problems with my file handling. The problem is very strange. The functions that I attached are all called from the Window Procedure. Here is a quick explanation. If I call the SaveAsText() function first, and use the SaveText() method, everything saves to the text file fine, when I look with notepad. But if I use the OpenText() or OpenTextDrop() function to open a text file, then try to use the SaveText() function, nothing goes to the text file at all. Can someone help me? _________________________________________________________________ Scan and help eliminate destructive viruses from your inbound and outbound e-mail and attachments. http://join.msn.com/?pgmarket=en-ca&page=byoa/prem&xAPID=1994&DI=1034&SU=http://hotmail.com/enca&HL=Market_MSNIS_Taglines Start enjoying all the benefits of MSN® Premium right now and get the first two months FREE*. |
|
From: Noorez K. <lor...@ho...> - 2005-12-17 01:40:11
|
I have a program that needs to read in a file only 500 chars at a time. I
found this example in a tutorial but am confused about a part of it.
ifstream file ("example.txt", ios::in|ios::binary|ios::ate);
if (file.is_open())
{
size = file.tellg();
memblock = new char [size];
file.seekg (0, ios::beg);
file.read (memblock, size);
file.close();
...
When file.read() is called, does it move the file pointer, or do i have to
do it? If i have to move it to read the next 500 chars, would i set the
pointer at the value 500?
_________________________________________________________________
Take charge with a pop-up guard built on patented Microsoft® SmartScreen
Technology
http://join.msn.com/?pgmarket=en-ca&page=byoa/prem&xAPID=1994&DI=1034&SU=http://hotmail.com/enca&HL=Market_MSNIS_Taglines
Start enjoying all the benefits of MSN® Premium right now and get the
first two months FREE*.
|
|
From: P.D. v. Z. <pd...@xs...> - 2004-01-14 20:22:52
|
Well, here's a version (didn't base it on your code, so variable names and
such are different). Note that it isn't very efficient though (it copies one
byte at a time).
#include <fstream>
#include <string>
#include <iostream>
using namespace std;
int main()
{
string from,to;
// Get filenames
cout << "Source file: ";
getline(cin, from);
cout << "Destination file: ";
getline(cin, to);
// Open files
ifstream is(from.c_str(), ios::binary);
ofstream os(to.c_str(), ios::binary);
if (!is.is_open() || !os.is_open())
{
cerr << "Unable to open files." << endl;
return 1;
}
// Create some iterators based on the file
unsigned char uc;
while (is)
{
uc = is.get();
if (is.eof())
break;
os.put(uc);
}
// Exit app
return 0;
}
If your application will only run on Windows (or Win32 systems in general),
you can use the "CopyFile" function defined in windows.h, which will
undoubtedly be faster.
Here's the declaration of this function, in case you're interested:
BOOL CopyFile(
LPCTSTR lpExistingFileName,
LPCTSTR lpNewFileName,
BOOL bFailIfExists
);
Hope this helped,
Paul
-----Original Message-----
From: dev...@li...
[mailto:dev...@li...] On Behalf Of Noorez
Kassam
Sent: Wednesday, January 14, 2004 7:59 PM
To: dev...@li...
Subject: [Dev-C++] File Handling
This is a code that should copy a .exe file. But i'm not sure what function
call to use to copy one bit at time. Can someone fill it in.
#include <iostream>
#include <cstdlib>
#include <fstream>
#include <string>
using namespace std;
int main()
{
ofstream out_file;
ifstream in_file;
cout << "Program copyer. The .exe extension will be added for you\n";
char name1[234];
cout << "Enter name of file: ";
cin.getline(name1, 234);
strcat(name1,".exe");
in_file.open(name1, ios::binary);
out_file.open("newfile.exe",ios::binary);
//code needed hear
system("pause");
}
_________________________________________________________________
Add photos to your e-mail with MSN 8. Get 2 months FREE*.
http://join.msn.com/?page=features/photos&pgmarket=en-ca&RU=http%3a%2f%2fjoi
n.msn.com%2f%3fpage%3dmisc%2fspecialoffers%26pgmarket%3den-ca
-------------------------------------------------------
This SF.net email is sponsored by: Perforce Software.
Perforce is the Fast Software Configuration Management System offering
advanced branching capabilities and atomic changes on 50+ platforms.
Free Eval! http://www.perforce.com/perforce/loadprog.html
_______________________________________________
Dev-cpp-users mailing list
Dev...@li...
TO UNSUBSCRIBE: http://www23.brinkster.com/noicys/devcpp/ub.htm
https://lists.sourceforge.net/lists/listinfo/dev-cpp-users
|
|
From: P.D. v. Z. <pd...@xs...> - 2004-01-14 20:25:04
|
Oops... the code also has some old comments in it ... I based it on some
other code I had lying around which read words from a file into a vector,
sorted them, and output only the unique words in alphabetical order... so
ignore the comments :D
Actually 'borrowed' that code from Stroustrup, I believe it was somewhere in
"The C++ Programming Language"... very elegant way of using iterators and
streams... too bad I couldn't use it for this problem (the formatted
input/output operators are used like that, which yields incorrect results
for binary files).
Paul
-----Original Message-----
From: dev...@li...
[mailto:dev...@li...] On Behalf Of Noorez
Kassam
Sent: Wednesday, January 14, 2004 7:59 PM
To: dev...@li...
Subject: [Dev-C++] File Handling
This is a code that should copy a .exe file. But i'm not sure what function
call to use to copy one bit at time. Can someone fill it in.
#include <iostream>
#include <cstdlib>
#include <fstream>
#include <string>
using namespace std;
int main()
{
ofstream out_file;
ifstream in_file;
cout << "Program copyer. The .exe extension will be added for you\n";
char name1[234];
cout << "Enter name of file: ";
cin.getline(name1, 234);
strcat(name1,".exe");
in_file.open(name1, ios::binary);
out_file.open("newfile.exe",ios::binary);
//code needed hear
system("pause");
}
_________________________________________________________________
Add photos to your e-mail with MSN 8. Get 2 months FREE*.
http://join.msn.com/?page=features/photos&pgmarket=en-ca&RU=http%3a%2f%2fjoi
n.msn.com%2f%3fpage%3dmisc%2fspecialoffers%26pgmarket%3den-ca
-------------------------------------------------------
This SF.net email is sponsored by: Perforce Software.
Perforce is the Fast Software Configuration Management System offering
advanced branching capabilities and atomic changes on 50+ platforms.
Free Eval! http://www.perforce.com/perforce/loadprog.html
_______________________________________________
Dev-cpp-users mailing list
Dev...@li...
TO UNSUBSCRIBE: http://www23.brinkster.com/noicys/devcpp/ub.htm
https://lists.sourceforge.net/lists/listinfo/dev-cpp-users
|
|
From: Per W. <pw...@ia...> - 2004-01-14 22:44:52
|
No need to copy one bit at the time. You wan't to copy as large blocks as
possible to keep code efficient. Create a reasonably large buffer - a
reasonably large number n * 4096 should be good - and then read/write
until done. Just notice that the last read/write block might be smaller.
/Per W
On Wed, 14 Jan 2004, Noorez Kassam wrote:
> This is a code that should copy a .exe file. But i'm not sure what function
> call to use to copy one bit at time. Can someone fill it in.
>
> #include <iostream>
> #include <cstdlib>
> #include <fstream>
> #include <string>
> using namespace std;
>
> int main()
> {
> ofstream out_file;
> ifstream in_file;
>
> cout << "Program copyer. The .exe extension will be added for you\n";
>
> char name1[234];
> cout << "Enter name of file: ";
> cin.getline(name1, 234);
> strcat(name1,".exe");
>
> in_file.open(name1, ios::binary);
> out_file.open("newfile.exe",ios::binary);
>
> //code needed hear
>
> system("pause");
> }
>
> _________________________________________________________________
> Add photos to your e-mail with MSN 8. Get 2 months FREE*.
> http://join.msn.com/?page=features/photos&pgmarket=en-ca&RU=http%3a%2f%2fjoin.msn.com%2f%3fpage%3dmisc%2fspecialoffers%26pgmarket%3den-ca
>
>
>
> -------------------------------------------------------
> This SF.net email is sponsored by: Perforce Software.
> Perforce is the Fast Software Configuration Management System offering
> advanced branching capabilities and atomic changes on 50+ platforms.
> Free Eval! http://www.perforce.com/perforce/loadprog.html
> _______________________________________________
> Dev-cpp-users mailing list
> Dev...@li...
> TO UNSUBSCRIBE: http://www23.brinkster.com/noicys/devcpp/ub.htm
> https://lists.sourceforge.net/lists/listinfo/dev-cpp-users
>
|