This topic has been archived. It cannot be replied.
-
工作学习 / 专业技术讨论 / USING iostream.h, 突然发现同时读写文件的情况下,没有办法APPEND文件.请问,谢谢.
-iwantcar(流浪的EnjoyStudying);
2006-6-15
(#3030590@0)
-
code here:fstream iofile (FileName, ios::in | ios::out | ios::binary| ios::ate);
//doing some reading and updating.....
iofile.seekp(sizeoffile, ios_base::beg);
iofile.write((char *)&c, 1); //nothing is written. try put function. same result.
-iwantcar(流浪的EnjoyStudying);
2006-6-15
{246}
(#3030601@0)
-
试了,没有问题。两个猜测:1、文件是只读的或被其它软件打开了;2、(char *)&c的内容不是你要写的东西,而是不可见的字符.#include <iostream>
#include <fstream>
using namespace std;
int main(void) {
fstream iofile ("c:\\tmp\\test.txt", ios::in | ios::out | ios::binary| ios::ate);
const char c = 'c';
char *s = new char[100];
iofile.seekg( 0, ios_base::end );
long sizeoffile = iofile.tellg();
iofile.seekg( 0, ios_base::beg );
iofile.read( s, 5 );
iofile.seekp(sizeoffile, ios_base::beg);
iofile.write((char *)&c, 1);
delete[] s;
return 0;
}
-canadiantire(轮胎-cui bono?);
2006-6-15
{474}
(#3030742@0)
-
ah. thanks. but I try and try.
-iwantcar(流浪的EnjoyStudying);
2006-6-15
(#3030751@0)
-
I try your code. it doesn't work. I am using visual c++ express version. what is your compiler?
-iwantcar(流浪的EnjoyStudying);
2006-6-15
(#3030775@0)
-
Oh, sorry, g++, I don't have VC6 on my machine now, maybe i should try on my vc2005...
-canadiantire(轮胎-cui bono?);
2006-6-15
(#3030807@0)
-
fxxk c++, it seems both vc and g++ has some bugs here and there.
-iwantcar(流浪的EnjoyStudying);
2006-6-15
(#3030816@0)
-
Maybe it is just some trival typos, for example, file name ?
-canadiantire(轮胎-cui bono?);
2006-6-15
(#3030825@0)
-
This is exactly the problem. Very good guess. You are even faster than I who is reading the code in visual C.
-iwantcar(流浪的EnjoyStudying);
2006-6-15
(#3030849@0)
-
try mingw g++. It desen't work neither. I am getting crazy..
-iwantcar(流浪的EnjoyStudying);
2006-6-15
(#3030823@0)
-
OK i tried on VC 2005, works like a charm.
-canadiantire(轮胎-cui bono?);
2006-6-15
{694}
(#3030817@0)
-
content of my c:\tmp\test.txtsdjfdslkjflds
dsf
dsf
sdf
ds
fds
fds
fds
f
dsf
dsf
dsf
-----------------------------
-iwantcar(流浪的EnjoyStudying);
2006-6-15
{98}
(#3030826@0)
-
sorry. I know the reason.
-iwantcar(流浪的EnjoyStudying);
2006-6-15
(#3030828@0)
-
The filename is not right in your code, because rolia cut the \\
-iwantcar(流浪的EnjoyStudying);
2006-6-15
(#3030829@0)
-
full code is here. It used to add some check sum per page in the database system.
代码死活调不通.先放这.也不知道是不是因为数据文件太大?This is the C code:
http://us.f13.yahoofs.com/bc/4405bf93mdc7255b0/bc/PLAYVC.cpp?bfz3bkEB.NyHGzkK
This is the data file.
http://us.f13.yahoofs.com/bc/4405bf93mdc7255b0/bc/Btree.BIN?bfz3bkEB5g3U.qu.
-iwantcar(流浪的EnjoyStudying);
2006-6-15
{202}
(#3030863@0)
-
shit. Problem is solved. C++ io stream, 笨重的傻瓜的 API.写两个月不到C++文件处理程序,其中化在IOSTREAM上的调试时间,起码有3天.I need to add after last read error.
iofile.clear();
This is not the first time I make such mistake..
-iwantcar(流浪的EnjoyStudying);
2006-6-15
{106}
(#3031236@0)
-
visual c
-iwantcar(流浪的EnjoyStudying);
2006-6-15
(#3030607@0)
-
不太懂.
-eagle_no1(瞎起哄);
2006-6-15
(#3030834@0)
-
question closed. 轮胎 is really good at programming.
-iwantcar(流浪的EnjoyStudying);
2006-6-15
(#3030843@0)
-
你是在夸他还是在骂他?
-eagle_no1(瞎起哄);
2006-6-15
(#3031026@0)
-
是他吗?还是她?
-iwantcar(流浪的EnjoyStudying);
2006-6-15
(#3031042@0)
-
轮胎?
-eagle_no1(瞎起哄);
2006-6-15
(#3031101@0)
-
which part you don't understand?
-iwantcar(流浪的EnjoyStudying);
2006-6-15
(#3030848@0)