|
Hello guys, i'm a c++ beginner
i'm trying to move or copy a text file into another binary file through this code but it doesn't work ;
#include <iostream>
#include <fstream>
const static int BUF_SIZE = 4096;
using std::ios_base;
int main(int argc, char** argv) {
std::ifstream in ( ("C:\\forTest.txt"), ios_base::in | ios_base::binary);
std::ofstream out ( ("C:\\Test.bin"), ios_base::out | ios_base::binary);
char buf[BUF_SIZE];
do {
in.read(&buf[0], BUF_SIZE);
out.write(&buf[0], in.gcount());
} while (in.gcount() > 0);
in.close();
out.close();
}
Then i want to know how to get the file information like, size, last modification...etc
Thanks in advance
|
|
|
|
|
In your last thread on CodeProject people stopped helping you. My guess is because you seem to want people to give you solutions rather than help you understand things yourself. That's not normally a popular thing around here.
My advice to all beginners is learn how to read reference material. The following link to a C++ reference is not using the Standard Template Library but does show one way to get the length of a file. Reference documentation for the STL does exist. I strongly urge you to learn to find/read and understand references to learn C++ from rather than posting messages in internet forums.
http://www.cplusplus.com/reference/clibrary/cstdio/ftell.html[^]
|
|
|
|
|
Hmm, Don't see any thing so bad in the code. But you can use just "buf" instead of &buf[0]. Also, I prefer this way
while(!in.eof())
{
in.read(buf, BUF_SIZE);
out.write(buf, in.gcount());
}
He never answers anyone who replies to him. I've taken to calling him a retard, which is not fair to retards everywhere.-Christian Graus
|
|
|
|
|
moody123 wrote: i'm trying to move or copy a text file into another binary file
What do you mean exactly ? Do you want to append it to an existing binary file (at the end, start, ...), create a new file with the exact same content as your text file, ... ?
moody123 wrote: but it doesn't work ;
Same question. What do you mean exactly by doesn't work ? What were you expecting and what did you get ?
Please be specific.
|
|
|
|
|
moody123 wrote: ...but it doesn't work ;
Which means?
moody123 wrote: Then i want to know how to get the file information like, size, last modification...etc
Have you looked into GetFileAttributes() ?
"Old age is like a bank account. You withdraw later in life what you have deposited along the way." - Unknown
"Fireproof doesn't mean the fire will never come. It means when the fire comes that you will be able to withstand it." - Michael Simmons
|
|
|
|
|
simply all what i wanted is copy a file into an other binary file!!!
and i've tried to replace &buf[0] with buf just as (VuNic) said, and it worked!!!
then about what (led mike) has said; the problem is that i've a deadline to do this and the course which related to doing this programe it's not about programming!! it's about data security!!!
so don't think that i'm just posting a thread to hear comments like yours!! of course you didn't try to work under pressure, deadline, and without any c++ background!!!
David i'll have a look on that.
|
|
|
|
|
Hi,
I am launching my application which is an MDI application which does some injection to the processes. After keeping my system idle for some time (40 min) I am getting "Insufficient system resources exist to complete the requested service." message. Same time I am checking with Application event viewer which shows following error message. We have installed Service Pack 3 for Windows XP.
---------------------------------------------------------------------------------------------------
Error
*****
The description for Event ID ( 20 ) in Source ( Google Update ) cannot be found. The local computer may not have the necessary registry information or message DLL files to display messages from a remote computer. You may be able to use the /AUXSOURCE= flag to retrieve this description; see Help and Support for details. The following information is part of the event: Network Request Error.
Error: 0x80042197. Http status code: 407.
Url=https://tools.google.com/service/update2
Trying config: source=IE, named proxy=proxych1.techmahindra.com:8080, bypass=*.techmahindra.com;10.*.*.*;172.*.*.*;192.*.*.*;<local>.
trying CUP:WinHTTP.
Send request returned 0x80042197. Http status code 407.
trying WinHTTP.
Send request returned 0x80042197. Http status code 407.
trying CUP:Browser.
Send request returned 0x80004005. Http status code 0.
Trying config: source=winhttp, direct connection.
trying CUP:WinHTTP.
Send request returned 0x80072ee2. Http status code 0.
trying WinHTTP.
Send request returned 0x80072ee2. Http status code 0.
trying CUP:Browser.
Send request returned 0x80004005. Http status code 0.
Trying config: source=auto, wpad=1, script=.
trying CUP:WinHTTP.
Send request returned 0x80072ee2. Http status code 0.
trying WinHTTP.
Send request returned 0x80072ee2. Http status code 0.
trying CUP:Browser.
Send request returned 0x80004005. Http status code 0
---------------------------------------------------------------------------------------------------
Please let us know what could be the problem out here. When I am trying to get GetLastError it gives me "0" as there is no problem.
Thanks
SNI
SNI
|
|
|
|
|
Hello, everyone
Recently I use g++ to compile cpp files with a -static paramter, and I got an compiler error as below:
/homes/judge/source/31.cpp:7:2: warning: no newline at end of file
ld: fatal: library -lm: not found
ld: fatal: library -lc: not found
ld: fatal: library -lc: not found
ld: fatal: File processing errors. No output written to /homes/judge/exe/4090
collect2: ld returned 1 exit status
I guess may be it happened by problem of system environment, the /etc/profile list out here:
<br />
MANPATH=$MANPATH:/usr/local/man<br />
LD_LIBRARY_PATH=/usr/local/lib:/usr/lib/ld:/usr/lib<br />
LD_LIBRARY_PATH=$LD_LIBRARY_PATH:/export/home/mysql/mysql-5.1.32/lib<br />
CC=gcc<br />
<br />
export LD_LIBRARY_PATH<br />
export CC<br />
export MANPATH<br />
<br />
<br />
JAVA_HOME=/Desktop/jdk1.6.0_12<br />
<br />
<br />
CLASSPATH=.:$JAVA_HOME/lib:$JAVA_HOME/jre/lib<br />
export CLASSPATH<br />
<br />
CATALINA_BASE=/usr/local/tomcat<br />
CATALINA_HOME=/usr/local/tomcat<br />
PATH=$PATH:$JAVA_HOME/bin:$JRE_HOME/bin:$CATALINA_HOME/bin:/usr/sfw/bin:/usr/local/bin:/usr/bin:/usr/ccs/bin:/sur/sbin<br />
export PATH
Any suggestion for this problem? Thanks in advance!
no cross no crown.
|
|
|
|
|
It seems that u r missing some static libraries
|
|
|
|
|
|
g++ should be able to find libc and libm (those are the two that you're having issues with). Are you sure Solaris supports static linking? I've just tried the same test on OS X (10.5.6) and, while gcc accepts -static, not all static libraries are present.
Java, Basic, who cares - it's all a bunch of tree-hugging hippy cr*p
|
|
|
|
|
Stuart Dootson wrote: g++ should be able to find libc and libm
You mean that I need add the path include the libc&libm into system environment? When I use -lm parameter it works, isn't -lm says g++ compiler is using the math library compiling code, namely the libm? But with a -static will occur that error.I confused that a little.
Stuart Dootson wrote: Are you sure Solaris supports static linking
I think the -static is belong to g++ and independence of platform(solaris/fedora..), but I am too new one to confirm this. I guess it due to a library g++ can't find.
The key is that I try writting a program about online judge program(some thing like ACM), it did not work well without the -static parameter while compiling period. I have to compile like this: g++ %s/%d.cpp -o %s/%d -ansi -fno-asm -Wall -lm -DONLINE_JUDGE --static 2> %s/%d.txt
I am very need your suggestions, thanks for your time!
no cross no crown.
|
|
|
|
|
Sorry, I google it, finally find the static linking on Solaris 10 was removed.
Now, I need to think changing to a linux server.
Thank you sir.
no cross no crown.
|
|
|
|
|
David Wong RZ wrote: Sorry, I google it, finally find the static linking on Solaris 10 was removed
No worries - glad you found an explanation for your problem!
Java, Basic, who cares - it's all a bunch of tree-hugging hippy cr*p
|
|
|
|
|
How to create window with Transparency level starts from 0 to 100%?
Left side transparency level = 0%
Right side transparency level = 100%
Is it possible to use AlphaBlend() API.
Is it possible to use GradientFill() method of CDC.
pls let me know with sample
|
|
|
|
|
|
Thanks 4 ur help.
Ur link is helpful, but it uses GDIplus and it is not my requirement.
I need to use only MFC.
Anyway it will b useful if u explain the method Refresh() of class CImgBaseDialog in more detailed manner.
I understood rest of the stuffs like hooking, unhooking, etc.,
Thanks n advance!!!
|
|
|
|
|
The sample uses the GDI+ to load PNG / TIFF image.
U can modify the code to use CXimage http://www.codeproject.com/KB/graphics/cximage.aspx[^] and normal GDI
The Refresh() method in CImgBaseDialog works as the following:
Paint the background first.
Enumerate all child controls, and for each of them, send WM_PRINT to get the captured bitmap, paint at the same place of the fake window.
Finally, caculate the position of caret, draw the caret.
----------------------------------------------------------------
English is not my native language
|
|
|
|
|
Hi All
Suppose i've a VC+ project. how ll i know wheather its a SDi or MDI or dailogbased project?
Regards
Phillip
Regards
Phillip
|
|
|
|
|
Cool_Phillip wrote: how ll i know wheather its a SDi or MDI or dailogbased project?
By looking at it?
"Old age is like a bank account. You withdraw later in life what you have deposited along the way." - Unknown
"Fireproof doesn't mean the fire will never come. It means when the fire comes that you will be able to withstand it." - Michael Simmons
|
|
|
|
|
DavidCrow wrote: By looking at it?
Hi
thanx for reply.
But how come i'll know the type by looking at code. my project doesn't ve any CFramewnd, or CDoc.
Regards
Phillip
|
|
|
|
|
Cool_Phillip wrote: But how come i'll know the type by looking at code.
Look at what is in the InitInstance() method.
"Old age is like a bank account. You withdraw later in life what you have deposited along the way." - Unknown
"Fireproof doesn't mean the fire will never come. It means when the fire comes that you will be able to withstand it." - Michael Simmons
|
|
|
|
|
Thank you very much.
Regards
Phillip
|
|
|
|
|
Try to create each one of the 3 types project, look at what is difference, the main difference is CMainFrame
|
|
|
|
|
Thank you very much.
Regards
Phillip
|
|
|
|