关于iostream库的有关问题,小弟我都快困惑死了
关于iostream库的问题,我都快困惑死了
打开文件,《think in c++》 用的是
#inlcude <fstream.h>
里边“打开一个已存在的文件”是用的
ifstream in(filename,ios::nocreate)
在《c++ primer》中,用的是std名字空间的 <fstream> ,创建文件输入流,在书上和vc自动完成功能中,没有找到“打开已存在文件”这样的参数。
1,在后者(std名字空间)的库中,如何打开已存在的文件?
2,为什么不同版本的库,接口都不统一?
3,哪里能找到相关标准的文档?
------解决方案--------------------
《think in c++》 不可能?
对了,你看的是第几版?
现在应该看第二版.
这是Volume 1 第111页上的例子!
//: C02:Scopy.cpp
// Copy one file to another, a line at a time
#include <string>
#include <fstream>
using namespace std;
int main() {
ifstream in( "Scopy.cpp "); // Open for reading
ofstream out( "Scopy2.cpp "); // Open for writing
string s;
while(getline(in, s)) // Discards newline char
out < < s < < "\n "; // ... must add it back
} ///:~
------解决方案--------------------
The I/O stream mode flags allow you to access files in different ways. The flags are:
Mode Meaning
ios::app append output
ios::ate seek to EOF when opened
ios::binary open the file in binary mode
ios::in open the file for reading
ios::out open the file for writing
ios::trunc overwrite the existing file
打开文件,《think in c++》 用的是
#inlcude <fstream.h>
里边“打开一个已存在的文件”是用的
ifstream in(filename,ios::nocreate)
在《c++ primer》中,用的是std名字空间的 <fstream> ,创建文件输入流,在书上和vc自动完成功能中,没有找到“打开已存在文件”这样的参数。
1,在后者(std名字空间)的库中,如何打开已存在的文件?
2,为什么不同版本的库,接口都不统一?
3,哪里能找到相关标准的文档?
------解决方案--------------------
《think in c++》 不可能?
对了,你看的是第几版?
现在应该看第二版.
这是Volume 1 第111页上的例子!
//: C02:Scopy.cpp
// Copy one file to another, a line at a time
#include <string>
#include <fstream>
using namespace std;
int main() {
ifstream in( "Scopy.cpp "); // Open for reading
ofstream out( "Scopy2.cpp "); // Open for writing
string s;
while(getline(in, s)) // Discards newline char
out < < s < < "\n "; // ... must add it back
} ///:~
------解决方案--------------------
The I/O stream mode flags allow you to access files in different ways. The flags are:
Mode Meaning
ios::app append output
ios::ate seek to EOF when opened
ios::binary open the file in binary mode
ios::in open the file for reading
ios::out open the file for writing
ios::trunc overwrite the existing file