刚刚在看C++对文件的操作,试用ofstream类向文件写东西。 代码是很简单的: ofstream ofs("2.txt"); ofs.write("hellohellohello",sizeof("hellohellohello")); ofs.close(); 然后得加一个头文件 fstream.h #include "stdafx.h" #include "FILE.h" #include "FILEDoc.h" #include "FILEView.h" #include <fstream.h> 问题是。。如果我把#include <fstream.h>放在如上所示的位置,编译就不报错。 如果把#include <fstream.h>放在 ...
by parrot18 - C/C++ - 2011-05-18 16:36:24 阅读(6071) 回复(7)
在Debian下面执行sudo make时,线上遇到了找不到gmake命令的问题,后来用sudo ln -s /usr/bin/make /usr/bin/gmake添加链接解决了该问题。 再执行sudo make时,出现了如下的错误问题。 cd ./src/app; gmake all gmake[1]: Entering directory `/home/jjj/svp-1.0b0/src/app' cd ../libvd; gmake all gmake[2]: Entering directory `/home/jjj/svp-1.0b0/src/libvd' c++ -c -funsigned-char -DLIBVD_VERSION=\"1.0b0\" -I. -I/usr...
各位大侠,小女子有一个程序一直出错,不知道是什么问题,请大家不吝赐教。感激不尽..... GB.DumDat是一个二维数组的文件,格式如下,数组应该是5列28行 [ 数字, 数字, 数字,数字 数字,数字,数字,数字 。。。。。 ] ifstream inpStr("dat3.blar"); if (inpStr.bad()) { cerr<<"Arr. read error... /n"; exit(1); } GB.DumDat.resize(Range(1,k),Range(1,6)); GB.DumDat=0; inpStr >> GB.DumDat; 就是这句出...
要用一个文件作为配置文件,比如config.txt,内容: ip: 10.0.0.111 port: 2222 现在要写程序,读取和修改配置参数。 如果用fstream来实现的话。读入好办,用>> 就可以了。但是修改有点麻烦。比如读入string 10.0.0.111后,怎样修改这个字串呢?初步的想法是写指针(用seekp())回退size()个位置,然后再写。可是有个问题,后写的字串长度可能超过原来字串长度,造成缓冲区溢出。这样需要把原来的字串留一些空格,保证最大情况...
使用stl,就意味着告别熟悉的c-style编程方式,对文件的处理也毫不例外. fstream可以用来对文件进行处理,它象对待数据流一样对待文件. 以下给出一个例子.关键是事先要创建fstream.out文件,哪怕是个空文件,也要先创建.因为fstream不会为你创建. #include #include int main ( ) { using namespace std; // create a bi-directional fstream object fstream inout("fstream.out"); // output c...
如果是如下代码: [code] fstream sfs; sfs.open("test.txt"); [/code] test.txt文件原来是没有的,像上面的这段代码就没有新生成test.txt文件。 把代码改成: [code] ofstream sfs; sfs.open("test.txt"); [/code] 就可以了,怎么回事啊
class A{ fstream fout; } class B{ setF( ? ){ fout = ?} fstream fout; } 要求将A中的fout传送给B中的fout.
以下两段代码 代码一 [code] int main() { fstream file; file.close(); file.open( "test" , std::ios_base::out ); file<<"adsfasf"; file.close(); system( "Pause" ); return 0; } [/code] 代码二 [code] #include <fstream> int main() { fstream file; file.open( "test" , std::ios_base::out ); file.close(); file.open( "test2" , std::ios_base::out ); file<<"adsfasf"; file.close(); system( ...